vaultmd / editFrontmatter
Function: editFrontmatter()
editFrontmatter(
content,mutate):object
Defined in: src/frontmatter/edit.ts:27
Apply a mutator callback to a note's frontmatter and return the rewritten file content. Preserves the existing YAML structure and only writes back changed keys. If the frontmatter is non-flat or the mutation would produce a non-flat result, the file is left untouched and outcome is 'unverifiable'.
Parameters
content
string
Raw UTF-8 content of the markdown file.
mutate
(fm) => void
Callback that receives a mutable copy of the frontmatter object. Add, update, or delete keys in place.
Returns
Object with the updated content string and an EditOutcome describing whether the frontmatter was changed.
content
content:
string
The rewritten file content (identical to input when outcome is not 'edited').
outcome
outcome:
EditOutcome
Whether the mutation produced a change, no change, or was skipped.
Example
const { content: updated, outcome } = editFrontmatter(raw, (fm) => {
fm.status = 'done';
});