Add frontmatter crate for YAML frontmatter ser/de with serde integration #2792
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.
Summary
Adds a new
crates/frontmattercrate that provides a genericDocument<T>type for parsing and serializing markdown files with YAML frontmatter. The crate supports native serde integration, allowingDocument<T>to be embedded in other serde formats (JSON, YAML, etc.).This consolidates the frontmatter handling pattern currently duplicated across
granola,hooks, anddeeplink2plugins.API:
Key feature: YAML keys are automatically sorted alphabetically (recursively for nested structures) to ensure deterministic output regardless of insertion order.
Updates since last revision
test_sorted_keys,test_nested_sorted_keys) - now 12 tests totalReview & Testing Checklist for Human
serde_yaml::Valuebefore serializing, which means struct fields are also sorted alphabetically (e.g.,{title, tags}becomes{tags, title}). If preserving struct field declaration order matters, this needs adjustment.---\n{yaml}---\n\n{content}. Existing code usesformat!("---\n{}---\n", yaml)(single newline after closing delimiter). Confirm this difference is acceptable.---\n---), it parses"{}"which works for HashMap/Default types but may fail for required-field structs.Suggested test plan:
cargo test -p frontmatter(12 tests pass)Notes
Link to Devin run: https://app.devin.ai/sessions/37d3adedfd034b8896917d3f15bda735
Requested by: yujonglee (@yujonglee)