cartulary 0.3.0-alpha.1

The knowledge layer of your project — decisions, issues, docs, all in one place.
Documentation
//! Production renderer for [`PagesError`]. English wording lives on
//! the infra side of the domain/infra boundary — the natural seam
//! where i18n will hook in.

use crate::domain::model::site::Source;
use crate::domain::usecases::site::pages_walker::PagesError;

pub fn render(err: &PagesError) -> String {
    match err {
        PagesError::MissingTitle { source } => {
            format!("page {source} is missing the required `title:` frontmatter")
        }
        PagesError::BadFrontmatter { source, reason } => {
            format!("frontmatter in {source} is invalid: {reason}")
        }
        PagesError::BadSlug {
            source,
            segment,
            offending,
        } => format!(
            "page {source} has an invalid segment {segment:?}: \
             character {offending:?} is not allowed"
        ),
        PagesError::EmptySlug { source, segment } => {
            format!("page {source} segment {segment:?} produces an empty slug")
        }
        PagesError::BundleClash { directory } => format!(
            "directory {directory} contains both `_index.md` and `index.md`; \
             only one is allowed"
        ),
        PagesError::DuplicateUrl { url, sources } => {
            let listed = sources
                .iter()
                .map(Source::to_string)
                .collect::<Vec<_>>()
                .join(", ");
            format!("URL {url} is produced by multiple pages: {listed}")
        }
    }
}