Honor markdown.preserveFrontmatterOrder when writing updated frontmatter#158
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix ignore of preserveFrontmatterOrder config flag
Honor May 12, 2026
markdown.preserveFrontmatterOrder when writing updated frontmatter
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #158 +/- ##
==========================================
+ Coverage 64.65% 65.47% +0.81%
==========================================
Files 57 57
Lines 2340 2410 +70
Branches 369 389 +20
==========================================
+ Hits 1513 1578 +65
- Misses 827 832 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR wires markdown.preserveFrontmatterOrder through the update/write flows so that when frontmatter is updated, existing YAML key order is preserved (and newly added keys are appended) instead of being potentially reordered during serialization.
Changes:
- Extend frontmatter serialization to optionally preserve original top-level key ordering using the raw source content.
- Thread
preserveFrontmatterOrderfrom CLI commands through workflows intoupdateFrontmatterTool. - Add unit tests covering default (preserve) and disabled (object-order) behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/tools/updateFrontmatterTool.test.ts | Adds coverage for preserved vs non-preserved frontmatter key ordering. |
| src/utils/frontmatter.ts | Implements key-order extraction and ordered serialization logic. |
| src/tools/update-frontmatter/updateFrontmatterTool.ts | Adds preserveFrontmatterOrder input and passes raw content into serialization. |
| src/workflows/optimizeSeoWorkflow.ts | Threads ordering option into frontmatter updates in SEO workflow. |
| src/workflows/prepareDraftWorkflow.ts | Threads ordering option into cover-field frontmatter updates. |
| src/workflows/generateAndAttachCoverWorkflow.ts | Threads ordering option into cover-field frontmatter updates. |
| src/cli/commands/seo.ts | Passes config ordering flag into SEO workflow. |
| src/cli/commands/prepare.ts | Passes config ordering flag into prepare workflow. |
| src/cli/commands/fix.ts | Passes config ordering flag into fix flow’s frontmatter updates. |
| src/cli/commands/cover.ts | Passes config ordering flag into cover workflow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
mayashavin
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
markdown.preserveFrontmatterOrderwas accepted in config but not used when serializing frontmatter, so updates could reorder existing keys. This change threads the flag through update paths and preserves original YAML key order (with new keys appended) when enabled.Frontmatter serialization now supports stable key ordering
stringifyFrontmatterto accept serialization options:preserveFrontmatterOrderoriginalRawContentgray-matter.stringify.updateFrontmatterToolnow honors ordering modepreserveFrontmatterOrderinput (defaulttrue).stringifyFrontmatter.Config flag is now wired through write flows
config.markdown.preserveFrontmatterOrderfrom CLI commands into workflows/tools that callupdateFrontmatterTool(seo,fix,prepare,cover, and relevant workflows), so runtime behavior matches configuration.Focused coverage for enabled/disabled behavior