flatpage 2.0.0

A simple filesystem-based Markdown page loader
Documentation
//! Frontmatter types and metadata hooks.

use serde::de::DeserializeOwned;

/// Default frontmatter fields used by [`crate::FlatPage`].
#[derive(Debug, serde::Deserialize)]
pub struct DefaultFrontmatter {
    /// Optional explicit page title from frontmatter.
    pub title: Option<String>,
    /// Optional description from frontmatter.
    pub description: Option<String>,
}

/// Frontmatter hooks for [`crate::FlatPage`].
///
/// Types do not need to implement this trait to be parsed, but
/// [`crate::FlatPage::title`] is only available when they do.
pub trait TitleFrontmatter: DeserializeOwned {
    /// Returns an explicit title from frontmatter, if one was provided.
    fn title(&self) -> Option<&str> {
        None
    }
}

impl TitleFrontmatter for DefaultFrontmatter {
    fn title(&self) -> Option<&str> {
        self.title.as_deref()
    }
}