feat(render): add anchor extraction during markdown rendering

- Add Anchor struct with id, label, level fields
- markdown_to_html() now returns (String, Vec<Anchor>) tuple
- Headings h2-h6 are extracted with slugified IDs
- Add toc: bool frontmatter field for per-page TOC opt-in
- All heading tags now include id attributes for anchor links
This commit is contained in:
Timothy DeHerrera
2026-02-01 09:31:54 -07:00
parent d50a8c3fbe
commit a59b8ff2ab
3 changed files with 85 additions and 13 deletions

View File

@@ -50,6 +50,8 @@ pub struct Frontmatter {
pub section_type: Option<String>,
/// Override template for this content item
pub template: Option<String>,
/// Enable table of contents (anchor nav in sidebar)
pub toc: Option<bool>,
}
/// A content item ready for rendering.
@@ -144,6 +146,7 @@ fn parse_frontmatter(path: &Path, parsed: &gray_matter::ParsedEntity) -> Result<
let nav_label = pod.get("nav_label").and_then(|v| v.as_string().ok());
let section_type = pod.get("section_type").and_then(|v| v.as_string().ok());
let template = pod.get("template").and_then(|v| v.as_string().ok());
let toc = pod.get("toc").and_then(|v| v.as_bool().ok());
// Handle nested taxonomies.tags structure
let tags = if let Some(taxonomies) = pod.get("taxonomies") {
@@ -174,6 +177,7 @@ fn parse_frontmatter(path: &Path, parsed: &gray_matter::ParsedEntity) -> Result<
nav_label,
section_type,
template,
toc,
})
}