larablog 0.1.0

Markdown blogs for Laravel Rust in several languages, where every language has its own URL.
Documentation
use std::fmt;
use std::path::PathBuf;

/// What can go wrong reading a collection.
#[derive(Debug)]
pub enum Error {
    /// A post file that cannot be read: its frontmatter is not valid YAML.
    InvalidPost(String),
    /// A file or folder that cannot be read or written.
    Io(PathBuf, std::io::Error),
    /// A collection that `config.collections` does not name.
    UnknownCollection(String),
    /// The `LarablogServiceProvider` is not registered.
    NotRegistered,
}

impl fmt::Display for Error {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidPost(message) => formatter.write_str(message),
            Self::Io(path, error) => write!(formatter, "{}: {error}", path.display()),
            Self::NotRegistered => formatter.write_str("Larablog is not registered: add the LarablogServiceProvider."),
            Self::UnknownCollection(name) => write!(
                formatter,
                "There is no Larablog collection called `{name}` in the configuration."
            ),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Io(_, error) => Some(error),
            _ => None,
        }
    }
}