orbit_md/models/front_matter.rs
1//! Strongly typed YAML front matter extracted from Markdown sources.
2
3use serde::Deserialize;
4
5/// Metadata block at the top of a Markdown file.
6///
7/// All fields are optional at the serde layer so missing or partial front
8/// matter never panics the compiler. Malformed YAML is reported per file.
9#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)]
10pub struct FrontMatter {
11 /// Page title; falls back to filename stem when absent.
12 #[serde(default)]
13 pub title: Option<String>,
14
15 /// Optional publication date string (opaque to the engine).
16 #[serde(default)]
17 pub date: Option<String>,
18
19 /// Taxonomy tags rendered in the layout when present.
20 #[serde(default)]
21 pub tags: Vec<String>,
22
23 /// When `true`, the page is skipped during compilation.
24 #[serde(default)]
25 pub draft: bool,
26
27 /// Optional layout override relative to the template directory.
28 #[serde(default)]
29 pub layout: Option<String>,
30
31 /// Arbitrary string metadata preserved for template helpers.
32 #[serde(default)]
33 pub description: Option<String>,
34}
35
36impl FrontMatter {
37 /// Returns the effective title, using `fallback` when none was declared.
38 pub fn effective_title(&self, fallback: &str) -> String {
39 self.title.clone().unwrap_or_else(|| fallback.to_owned())
40 }
41}