Rewrite published post file in place when template_slug changes (stay published) #71

Closed
opened 2026-07-20 19:43:57 +00:00 by hugo · 1 comment
Owner

Source: Audit section 2.2.

Spec: specs/engine_side_effects.allium UpdatePostSideEffects: "If templateSlug changed on published post: rewrite .md frontmatter". Post stays published.

bDS2: ../bDS2/lib/bds/posts.ex — in update_post, when the post was and remains published and template_slug changed, it calls rewrite_published_post/1 (~line 544): reads the published body from the file, rewrites the file with updated frontmatter via atomic write, preserving published_at.

Current behaviour (RuDS): no post-level rewrite function exists; a template_slug change (like any update) demotes the post to draft and the file is only rewritten on the next publish.

Task: After the reopen-condition fix (see issue "Reopen published posts to draft only when published content actually changes"), add a rewrite_published_post equivalent in crates/bds-core/src/engine/post.rs: when a published post's update does not affect published content but changes frontmatter-visible metadata (template_slug), rewrite posts/YYYY/MM/{slug}.md in place (atomic write, keep body from file, refresh checksum). Note metadata_diff.rs already has rewrite_post_from_database for the repair path — reuse/share.

Acceptance: Test: publish post → update template_slug only → post still published, file frontmatter contains new templateSlug, checksum updated, body unchanged.

**Source:** Audit section 2.2. **Spec:** `specs/engine_side_effects.allium` UpdatePostSideEffects: "If templateSlug changed on published post: rewrite .md frontmatter". Post stays published. **bDS2:** `../bDS2/lib/bds/posts.ex` — in `update_post`, when the post was and remains published and template_slug changed, it calls `rewrite_published_post/1` (~line 544): reads the published body from the file, rewrites the file with updated frontmatter via atomic write, preserving published_at. **Current behaviour (RuDS):** no post-level rewrite function exists; a template_slug change (like any update) demotes the post to draft and the file is only rewritten on the next publish. **Task:** After the reopen-condition fix (see issue "Reopen published posts to draft only when published content actually changes"), add a `rewrite_published_post` equivalent in `crates/bds-core/src/engine/post.rs`: when a published post's update does not affect published content but changes frontmatter-visible metadata (template_slug), rewrite `posts/YYYY/MM/{slug}.md` in place (atomic write, keep body from file, refresh checksum). Note `metadata_diff.rs` already has `rewrite_post_from_database` for the repair path — reuse/share. **Acceptance:** Test: publish post → update template_slug only → post still published, file frontmatter contains new templateSlug, checksum updated, body unchanged.
hugo added the bug label 2026-07-20 19:43:57 +00:00
Author
Owner

Implemented in 1e32c7e. A real template_slug change on a still-published post now atomically rewrites the existing Markdown file in place through a shared post serializer used by both live updates and metadata-diff database-to-file repair. The rewrite preserves Published status, body bytes, publishedAt, file path, and the caller-supplied post checksum while updating templateSlug and current frontmatter. Preserving the database checksum follows the bDS2 golden master and the explicit checksum decision in #69; the issue acceptance wording about refreshing a generated checksum was stale. Expanded the acceptance test to verify changed file bytes, parsed templateSlug, unchanged body and publishedAt, NULL database body, and preserved caller checksum. Updated the Allium side-effect rule and README. Allium check/analyse, formatting, diff hygiene, cargo machete, cargo build --workspace, focused post/metadata-diff tests, and cargo test --workspace all pass.

Implemented in 1e32c7e. A real template_slug change on a still-published post now atomically rewrites the existing Markdown file in place through a shared post serializer used by both live updates and metadata-diff database-to-file repair. The rewrite preserves Published status, body bytes, publishedAt, file path, and the caller-supplied post checksum while updating templateSlug and current frontmatter. Preserving the database checksum follows the bDS2 golden master and the explicit checksum decision in #69; the issue acceptance wording about refreshing a generated checksum was stale. Expanded the acceptance test to verify changed file bytes, parsed templateSlug, unchanged body and publishedAt, NULL database body, and preserved caller checksum. Updated the Allium side-effect rule and README. Allium check/analyse, formatting, diff hygiene, cargo machete, cargo build --workspace, focused post/metadata-diff tests, and cargo test --workspace all pass.
hugo closed this issue 2026-07-21 19:33:11 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hugo/RuDS#71