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}")
}
}
}