Skip to content

Honor markdown.preserveFrontmatterOrder when writing updated frontmatter#158

Merged
mayashavin merged 4 commits into
mainfrom
copilot/fix-preserve-frontmatter-order
May 13, 2026
Merged

Honor markdown.preserveFrontmatterOrder when writing updated frontmatter#158
mayashavin merged 4 commits into
mainfrom
copilot/fix-preserve-frontmatter-order

Conversation

Copilot AI commented May 12, 2026

Copy link
Copy Markdown
Contributor

markdown.preserveFrontmatterOrder was 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

    • Extended stringifyFrontmatter to accept serialization options:
      • preserveFrontmatterOrder
      • originalRawContent
    • Added logic to extract original top-level frontmatter key order from the source YAML and rebuild the output object in that order before gray-matter.stringify.
    • New keys introduced by updates are appended after existing keys.
  • updateFrontmatterTool now honors ordering mode

    • Added optional preserveFrontmatterOrder input (default true).
    • Passes raw source content + ordering mode into stringifyFrontmatter.
  • Config flag is now wired through write flows

    • Propagated config.markdown.preserveFrontmatterOrder from CLI commands into workflows/tools that call updateFrontmatterTool (seo, fix, prepare, cover, and relevant workflows), so runtime behavior matches configuration.
  • Focused coverage for enabled/disabled behavior

    • Added tests to validate:
      • original key order is preserved by default
      • disabling the flag falls back to object-order serialization behavior
const updatedContent = stringifyFrontmatter(updatedFrontmatter, draft.markdownBody, {
  preserveFrontmatterOrder,
  originalRawContent: draft.rawContent,
});

Copilot AI changed the title [WIP] Fix ignore of preserveFrontmatterOrder config flag Honor markdown.preserveFrontmatterOrder when writing updated frontmatter May 12, 2026
Copilot AI requested a review from mayashavin May 12, 2026 11:20
@mayashavin mayashavin marked this pull request as ready for review May 12, 2026 11:26
Copilot AI review requested due to automatic review settings May 12, 2026 11:26
@codecov-commenter

codecov-commenter commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.42105% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.47%. Comparing base (a193e33) to head (d59e6eb).

Files with missing lines Patch % Lines
src/cli/commands/cover.ts 0.00% 1 Missing ⚠️
src/cli/commands/fix.ts 0.00% 1 Missing ⚠️
src/cli/commands/prepare.ts 0.00% 1 Missing ⚠️
src/cli/commands/seo.ts 0.00% 1 Missing ⚠️
src/utils/frontmatter.ts 98.27% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 preserveFrontmatterOrder from CLI commands through workflows into updateFrontmatterTool.
  • 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.

Comment thread src/utils/frontmatter.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@mayashavin mayashavin merged commit 6c8af7a into main May 13, 2026
9 checks passed
@mayashavin mayashavin deleted the copilot/fix-preserve-frontmatter-order branch May 13, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preserveFrontmatterOrder config flag is accepted but silently ignored

4 participants