use std::{fmt::Display, io};
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use std::error::Error;
#[derive(Debug, Serialize, Deserialize)]
pub struct BlogJson {
pub title: String,
pub date: NaiveDate,
pub desc: Option<String>,
pub slug: String,
pub tags: Vec<String>,
pub keywords: Option<Vec<String>>,
pub canonical_link: Option<String>,
pub author_name: Option<String>,
pub author_webpage: Option<String>,
pub last_modified: Option<NaiveDate>, pub priority: Option<f64>, }
#[derive(Debug)]
pub enum BlogError {
File(io::Error),
Markdown(String),
FileNotFound, ImproperDate(String),
ImproperFileName(String),
}
impl Error for BlogError {}
impl Display for BlogError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BlogError::File(a) => write!(f, "File read error caused by: {}", a),
BlogError::Markdown(b) => write!(f, "Markdown rendering error caused by: {}", b),
BlogError::FileNotFound => write!(f, "File not found"),
BlogError::ImproperDate(c) => write!(f, "Found date `{}` which appears to be improper - dates should be in the yyyy-mm-dd format", c),
BlogError::ImproperFileName(d) => write!(f, "Found file name `{}` which appears to be improper", d),
}
}
}