Skip to main content

populate

Function populate 

Source
pub fn populate(
    graph: &mut DepGraph,
    content_dir: &Path,
    template_dir: &Path,
    build_dir: &Path,
) -> Result<(), SsgError>
Expand description

Reads every .md file under content_dir and every .html file under template_dir, recording:

  • a content → template edge for each layout: frontmatter value (layout: "post" resolves to <template_dir>/<locale>/post.html when a localised copy exists, otherwise <template_dir>/post.html);
  • a template → template edge for each {{#extends "name"}} and {{->partial}} reference inside the template;
  • the canonical output path <build_dir>/<stem>/index.html (or <build_dir>/index.html for index.md);
  • the SHA-256 freshness key for every source touched.

Self-edges (page → page) are always recorded so deleting a page invalidates its own output. Missing template files don’t fault — the build will fail later with a friendlier message.

§Examples

use ssg::depgraph::{DepGraph, populate};
use tempfile::tempdir;
use std::fs;

let dir = tempdir().unwrap();
let content = dir.path().join("content");
let templates = dir.path().join("templates");
let build = dir.path().join("build");
fs::create_dir(&content).unwrap();
fs::create_dir(&templates).unwrap();
let mut g = DepGraph::new();
// Walking empty trees is a no-op.
populate(&mut g, &content, &templates, &build).unwrap();
assert_eq!(g.page_count(), 0);