Studio slice 2: architecture
By studio-architect, 2026-11-12, against the working tree at 46e176b. admin.rs = crates/openblog-cli/src/admin.rs, fm.rs = crates/openblog-core/src/frontmatter.rs. Answers the brief's A1–A4.
A1. Files kept as written#
- Today:
save_document(admin.rs:16758) rebuilds the whole file withfrontmatter::compose(fm.rs:597). That puts known keys inKEY_ORDERand the rest alphabetically, drops empties (cover: ""), turns inline lists into block lists, quotestrue(quote_scalar, :622), strips the body's leading blank lines (:615), and loses#comments (parse_fieldsskips them, :115). - Change:
pub fn splice(original, fields, body) -> Option<String>infm.rs.save_documentuses it when the request has"frontMatter": "keep"and the file exists, falls back tocomposeonNone, and replies"layout": "kept" | "rewritten". The request key isfrontMatterbecauselayout: recipeis already a legacy recipe marker in front matter. - Algorithm:
- Spans: split the front matter into spans: a top-level
key:line, its indented or-lines, and comments or blank lines between items. - Unchanged keys: keep their bytes.
- Changed scalars: keep their quoting style; a value that was bare
true/false, anddraft, is written bare; a trailing# commentstays. - Changed lists: keep inline or block form.
- Emptied or removed keys: delete only their span.
job.*andfaq.*: regenerate as a whole span.- New keys: go next to their
KEY_ORDERneighbour; unknown keys go at the end. - Body: kept byte-for-byte when unchanged; otherwise it keeps the original line ending, and a final newline only if the original had one.
- Self-check:
parse(result)must equal the request (minus empties), elseNone. - Edge cases: BOM, CRLF, no front matter.
- Spans: split the front matter into spans: a top-level
- Default later: keep is opt-in for slice 2 and becomes the default once the whole suite passes with it on. The one sensitive existing test is the claims-anchor test (admin.rs:24024).
A1b. Recipe fields#
- Fields (
recipe.rs:238–268, first alias wins):servings/servesprepTime/prep/prep_timecookTime/cook/cook_timetotalTime/totalyield/makescourse/category/recipeCategorycuisineadaptedFrom/basedOn
- Gap:
profile::field_aliases(profile.rs:350) only listscourse's aliases. Add the rest, and Studio edits whichever alias the post already uses, soprepTimenever shadows herprep. - Body the site understands (
markdown.rs:1599–1697,recipe::classify_heading):- the story, then
## Ingredientswith amount-first-items (### For the crustsub-groups allowed); ## Stepswith1.items, where times become timer buttons (ob-quantity.jsfindDurations);## Grammi's notes(any same-level heading ends a section).
- the story, then
- Server offers:
meta.profiles(the recipe starter, fields, help);POST preview→recipeProblems(codes inrecipe_check.rs:29; the old Admin's sentences areRECIPE_ADVICE, admin.js:8029).
A2. Delete and undo#
- Today:
DELETE document?path=(admin.rs:17292) moves the post and its sidecars (credits, track, contexts) to.openblog/trash/<stamp>-<rel with / → _>and replies withtrashedTo,trashedCreditsTo,trashedTrackToandtrashedContextTo. It has no etag check and no restore. - New route:
POST document/restore {path, trashedTo, trashedCreditsTo?, trashedTrackTo?, trashedContextTo?[]}.- Checks: bare names inside the trash that end with the name expected for
path. - Restore: moves the files back transactionally under the content lock, then rebuilds.
- Errors: 404 "no longer in the bin"; 409 when the path is taken or locked; 422 for names that don't match.
- Checks: bare names inside the trash that end with the name expected for
- Undo means: put back exactly what was moved, while the name is free and the trash file still exists. Re-sending the post from Studio's memory is not safe: it loses sidecars and can rename the file.
- Decision (stakeholder delegate): delete and restore trigger
auto_publishlike a save does, so a deleted post leaves the readers' site and comes back on Undo.
A3. Preview#
- Route:
POST preview {kind, path, fields, body}builds the site in memory and returnspreviewUrl(/admin/api/preview/<hex>, session-only, own CSP with inline scripts). The last 16 previews are kept, across all users. It also returnsrecipeProblems. - Studio's frame:
<iframe sandbox="allow-scripts">, withoutallow-same-origin, as in the old Admin (admin.js:21970). Studio's CSP already hasframe-src 'self'. Timers run inside the preview's own page. - When it builds: on request only, since each preview builds the whole site. A 404 asks for a fresh one.
A4. Pictures#
- Upload:
POST upload?name=takes raw bytes. PNG, JPEG, GIF, WebP and AVIF are accepted; HEIC is refused in a plain sentence. Photos are resized to 2000 px with location data removed, capped atmaxUploadMb, and saved understatic/images/uploads/<year>/. - List:
GET imagesreturns the newest 300 as{url, name}plusmore. - Missing: delete, rename, stored descriptions and usage checks. A description lives only in the post (
coverAlt,). Picture delete is deferred: the trash can't restore static files. - Library in slice 2: list, upload, and insert at the cursor.
Risks#
| Risk | Cover |
|---|---|
| Alt text or file names breaking Markdown | DOM-free escaper for ], \ and newlines; url must start with /images/uploads/; tests. |
| Preview scripts | Sandbox without allow-same-origin; a browser test checks it. |
| Recipe editor losing text | The body parser must round-trip exactly, or the post opens in the plain Words box. Tested on every Grammi post. |
| Splice errors | Self-check plus compose fallback; the reply says layout. |
prepTime overriding prep | field_aliases fix. |
| Undo in a toast times out (WCAG 2.2.1) | Undo lives in an alert-banner that stays until dismissed. |
write.js growing | Split the save and conflict flow out first. |
Files#
- Server
fm.rs(splice+ tests)profile.rs(aliases)admin.rs(keep flag,restore_document, route)admin/tests/document_keep_routes.rs,document_restore_routes.rs
- Screens
screens/pictures.js(new)screens/write.js(slimmed)screens/index.js(Pictures;#/write/new/recipe)
- Parts
- Browser:
save-flow.js(split from Write),recipe-editor.js,picture-picker.js(fromcover-picker.js),preview.js,delete.js - DOM-free:
recipe-body.js,recipe-fields.js,recipe-advice.js,image-markdown.js
- Browser:
- Tests
- Node:
studio-recipe-body,-recipe-fields,-recipe-advice,-image-markdown - Browser:
studio-recipe,-pictures,-preview,-delete-undo, and a round trip over a Grammi-shaped fixture site
- Node: