Skip to main content

validate_frontmatter

Function validate_frontmatter 

Source
pub fn validate_frontmatter(
    fields: &HashMap<String, String>,
    schema: &ContentSchema,
    file_path: &Path,
    fm_start_line: usize,
) -> Vec<ValidationError>
Expand description

Validates a frontmatter map against a ContentSchema.

Returns a list of errors (empty on success). file_path and fm_start_line are used only for error reporting.

ยงExamples

use ssg::content::{parse_schemas, validate_frontmatter};
use std::collections::HashMap;
use std::path::Path;

let schemas = parse_schemas(r#"
[[schemas]]
name = "post"
fields = [
  { name = "title", type = "string", required = true },
]
"#).unwrap();
let mut fm = HashMap::new();
fm.insert("title".to_string(), "Hello".to_string());
let errs = validate_frontmatter(&fm, &schemas[0], Path::new("a.md"), 1);
assert!(errs.is_empty());