Skip to the plan
Page-first

Implementation plan

Edit the page. The Google Doc keeps the words.

An author changes words, images, and layout on a preview of the page. Commit writes those changes into the Doc. Publish renders the last committed revision and uploads a static snapshot to Cloudflare. Sign-in is Google, and edit rights are whatever Google already grants on that Doc.

Google Doc

The canonical page

Written by Commit

Editor draft

Uncommitted page structure

Written by Typing, images, layout

Cloudflare

Static HTML, CSS, and copied assets

Written by Publish

The preview is a draft. After every commit the server re-reads the Doc, and the editor renders that result.

One pass through a page

  1. 01

    Open

    The signed-in token reads the Doc. The parser builds the page. Named ranges are the anchors.

  2. 02

    Edit

    Words, images, and block order change the draft. Keystrokes stay in the browser.

  3. 03

    Commit

    Operations become a Docs batchUpdate. A revision that moved returns 409 and writes nothing.

  4. 04

    Publish

    The same renderer runs in publish mode. Images leave Drive. HTML on that URL is purged.

Where this sits

Edge Delivery Services document authoring is doc-first. The author writes in a Google Doc, preview turns that Doc into HTML, and publish copies the result to the CDN.

DA.live is page-first. Its editor loads HTML from the source API and writes HTML back. Preview and publish happen after that write.

This app uses the page-editing gesture and keeps the Doc as the source. The CDN holds a snapshot of one revision and is never read back into the Doc.

Fixture · About

About the studio

A one-paragraph introduction.

hero

The work, plainly described.

Inline image

columns (contained)

Left columnFirst point.

Right columnSecond point.

The metadata table (title, description, template) is parsed and kept off the preview.

Doc contract

Ids live in named ranges, not in the text. Opening the Doc in Google shows ordinary headings, paragraphs, and tables. The first commit of an untagged Doc creates the ranges and changes no visible content.

How a page node sits in the Doc
Page nodeIn the DocRange
Section breakA paragraph whose text is ---pg/section/{id}
ProseHeading, paragraph, list, or imagepg/node/{id}
BlockA table. First cell is hero or columns (contained)pg/node/{id} on the table
Page metadataA two-column table named metadata. It is kept off the page.pg/meta
Section styleA section metadata table at the end of a sectionpg/node/{id}
Image bytesAn inline image after insert. Drive is the upload source.Inside the node range

Commit operations

The client sends the revision it loaded and a list of operations. The server resolves ranges, writes from the highest index downward, and re-reads the Doc before responding.

Operations the editor can commit
OperationDoc write
replaceTextReplace the text inside that named range and keep the paragraph style.
setBlockOptionsRewrite the parenthetical in the name cell.
setMetadataUpdate one row of the metadata table.
insertBlock / insertSectionInsert a table or a --- paragraph at the resolved index.
removeNodeDelete the content covered by the named range.
moveNodeRebuild the table at the destination, then delete the original. Docs has no move.
setImageTemporary link share, insertInlineImage, then remove the share.

Comments, suggestions, drawings, and unknown tables are opaque spans. A commit that would overlap one is rejected. The writer never replaces the document body.

Build order

A slice is done when its check passes against a real Google Doc. The Docs API is called in that slice, not mocked and deferred.

  1. 1

    Read a Doc into a preview

    Sign in with Google, open a Doc, and show it as a page. This slice proves the parser against a real document.

    Sign-in
    OAuth code with PKCE. Scopes: openid, documents, drive.file.
    Open
    A site folder the app created, or an existing Doc via the Picker.
    Parse
    Prose, --- section breaks, one table block, and the metadata table.
    Render
    A read-only preview. Metadata stays in the page head.

    Done when. The About fixture renders as a title, a hero, and a columns block. A Doc this account cannot edit shows Google's error.

  2. 2

    Edit words and commit them

    Inline text stays in a draft. Commit writes it through named ranges, then the server re-reads the Doc and the editor renders that result.

    Adopt
    The first commit creates named ranges and changes no visible text.
    Draft
    Keystrokes edit the page structure in the browser.
    Commit
    replaceText inside the named range. The server re-reads and returns the page.
    Conflict
    If the Doc revision moved, respond 409 and leave the draft unsent.

    Done when. The new sentence is visible in Google Docs itself. An edit made in Docs between load and commit returns 409 and writes nothing.

  3. 3

    Place images and move blocks

    Layout is reorder, insert, remove, and block options. The palette is prose, hero, columns, and cards. Image bytes end up stored in the Doc.

    Upload
    Bytes go to the site media folder. The draft stores the Drive file id.
    Insert
    Brief link-share, insertInlineImage, then remove the share.
    Move
    Rebuild the table at the destination and delete the original range.
    Protect
    A commit that would overlap a comment, drawing, or unknown table is rejected.

    Done when. Table order in the Doc matches the preview. The image still loads after the share is removed. A pre-existing comment is still on the Doc.

  4. 4

    Ship a static snapshot

    Publish renders the last committed revision with the same function as the preview, copies images off Drive, and uploads the directory.

    Gate
    Publish refuses while the draft has uncommitted operations.
    Render
    Publish mode strips contenteditable and draft ids.
    Assets
    Content-addressed image files. HTML points at those.
    Upload
    Cloudflare Pages Direct Upload. Local ./out when the token is absent.

    Done when. The public URL has no editor and no Google sign-in. Publishing the same revision again does not upload.

  5. 5

    A folder of pages

    The Drive folder is the site. Home is the doc named index. Shared chrome is a fragment Doc. Redirects are a Sheet.

    Paths
    Folder-relative path. index serves the site root.
    Fragments
    A fragment block points at another Doc. Publish inlines the resolved render.
    Redirects
    A Sheet named redirects maps an old path to a new one.
    Fan-out
    Editing the header fragment and publishing dependents updates each page.

    Done when. Two pages share one header. Publishing both after a header edit updates both. A redirects row publishes a redirect.

Where this breaks

Each of these is checked inside the slice that introduces it.

Risks and the slice that retires them
RiskWhat we doChecked in
Docs indexes shift on every editResolve named ranges on each commit. Re-read after writing. Never reuse an index.Slice 2
drive.file hides files the author expectsThe app creates the site folder. Existing docs enter through the Picker. The first screen says so.Slice 1
insertInlineImage requires a public URLLink-share for the insert call only. The Doc stores the bytes. Publish copies them out.Slice 3
A commit drops content the parser skippedOpaque spans reject an overlapping edit. The writer never replaces the body.Slice 3
Preview HTML and the public page divergeOne render function, two modes. Diff them with editor attributes removed.Slice 4
A dirty draft gets publishedPublish loads the revision from Google and refuses uncommitted operations.Slice 4

Decisions already made

Identity
Google OAuth only. A 403 from Google is the permission check.
Scopes
openid, documents, and drive.file. Existing docs come in through the Picker.
When the Doc changes
On commit, not on each keystroke.
Anchors
Named ranges pg/section, pg/node, and pg/meta. Indexes are never cached.
Layout
Reorder, insert, remove, and block options. Palette: prose, hero, columns, cards.
CDN
Cloudflare Pages Direct Upload. Local ./out when the token is absent.
Preview hostname
The editor is the preview until a second person needs a link.
Database
None, until something must publish without a person present.
Conflicts
409 and reload. No merge in the first version.
Stack
Next.js and TypeScript.

Left for later