Skip to content

preserveFrontmatterOrder config flag is accepted but silently ignored #116

@mayashavin

Description

@mayashavin

Problem

polira.config.ts accepts markdown.preserveFrontmatterOrder: true (default) as a documented configuration option (src/core/config.ts:47). However, src/utils/frontmatter.ts:29 calls matter.stringify(body, frontmatter) with no key-ordering logic.

gray-matter's stringify does not guarantee key order; it serialises frontmatter as a plain object, so existing frontmatter field order is not preserved when updateFrontmatterTool writes changes.

Expected behaviour

When preserveFrontmatterOrder: true (the default), stringifyFrontmatter should reconstruct the YAML block with original key order intact, inserting new fields at the end.

When preserveFrontmatterOrder: false, the current behaviour (arbitrary serialisation order) is acceptable.

Files affected

  • src/utils/frontmatter.tsstringifyFrontmatter function
  • src/tools/update-frontmatter/updateFrontmatterTool.ts
  • src/core/config.ts — config schema entry

Suggestion

Preserve the original key order by building the updated frontmatter object with original keys first, then appending new keys. Pass that ordered object to matter.stringify.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions