Skip to main content

emit_sidecars

Function emit_sidecars 

Source
pub fn emit_sidecars(content_dir: &Path, sidecar_dir: &Path) -> Result<usize>
Expand description

Emits .meta.json sidecar files for all Markdown content.

Walks content_dir for .md files, extracts frontmatter via frontmatter-gen, and writes a JSON sidecar alongside each file in the same relative location under sidecar_dir.

These sidecars are consumed by TeraPlugin, JsonLdPlugin, and other plugins that need parsed frontmatter after compilation.

ยงExamples

use ssg::frontmatter::emit_sidecars;
use tempfile::tempdir;
use std::fs;

let dir = tempdir().unwrap();
let content = dir.path().join("content");
let sidecar = dir.path().join("sidecar");
fs::create_dir(&content).unwrap();
fs::write(content.join("a.md"), "---\ntitle: Hi\n---\nBody").unwrap();
let n = emit_sidecars(&content, &sidecar).unwrap();
assert_eq!(n, 1);