What's wrong
When a document already has frontmatter, AddFrontmatter parses it into a Dictionary<string, object>, adds the new keys, and serializes the whole dictionary again through ReplaceFrontmatter. Anything in the header that isn't a key/value pair is lost: comments disappear and the original formatting is rewritten, even though the caller only asked to add a property.
Repro
string doc = "---\n# Draft: do not publish until legal signs off\ntitle: Launch # working title\ntags: [a, b]\n---\nBody\n";
Console.Write(Frontmatter.AddFrontmatter(doc, new() { ["author"] = "Jane" }));
Observed:
---
title: Launch
tags:
- a
- b
author: Jane
---
Body
- The whole-line comment is gone.
- The inline
# working title comment is gone.
- The flow list
[a, b] has been turned into a block list.
Why it matters
Stamping a property such as a date, author or id onto many files is the main batch use of AddFrontmatter. Running it over a content repository silently removes editorial notes and commented-out settings from every file, and produces a large, noisy diff.
Suggested fix / acceptance criteria
What's wrong
When a document already has frontmatter,
AddFrontmatterparses it into aDictionary<string, object>, adds the new keys, and serializes the whole dictionary again throughReplaceFrontmatter. Anything in the header that isn't a key/value pair is lost: comments disappear and the original formatting is rewritten, even though the caller only asked to add a property.Repro
Observed:
# working titlecomment is gone.[a, b]has been turned into a block list.Why it matters
Stamping a property such as a date, author or id onto many files is the main batch use of
AddFrontmatter. Running it over a content repository silently removes editorial notes and commented-out settings from every file, and produces a large, noisy diff.Suggested fix / acceptance criteria
tags: [a, b]unchanged, and addsauthor: Jane.