Rewrite published post file in place when template_slug changes (stay published) #71
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Source: Audit section 2.2.
Spec:
specs/engine_side_effects.alliumUpdatePostSideEffects: "If templateSlug changed on published post: rewrite .md frontmatter". Post stays published.bDS2:
../bDS2/lib/bds/posts.ex— inupdate_post, when the post was and remains published and template_slug changed, it callsrewrite_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_postequivalent incrates/bds-core/src/engine/post.rs: when a published post's update does not affect published content but changes frontmatter-visible metadata (template_slug), rewriteposts/YYYY/MM/{slug}.mdin place (atomic write, keep body from file, refresh checksum). Notemetadata_diff.rsalready hasrewrite_post_from_databasefor 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.
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.