use chrono::NaiveDate;
use serde::Serialize;
#[derive(Serialize, Clone)]
pub struct SiteConfig {
pub title: String,
pub tagline: String,
pub header_title: String,
pub header_tagline: String,
pub base_url: String,
pub og_image: String,
pub twitter_handle: String,
pub posts_dir: String,
pub output_dir: String,
pub templates_dir: String,
pub static_dir: String,
pub css_file: String,
}
impl Default for SiteConfig {
fn default() -> Self {
Self {
title: "sblog".to_string(),
tagline: "A tiny static blog".to_string(),
header_title: "sblog".to_string(),
header_tagline: "A tiny static blog".to_string(),
base_url: String::new(),
og_image: String::new(),
twitter_handle: String::new(),
posts_dir: "posts".to_string(),
output_dir: "public".to_string(),
templates_dir: "templates".to_string(),
static_dir: "static".to_string(),
css_file: "static/style.css".to_string(),
}
}
}
#[derive(Clone)]
pub struct Post {
pub title: String,
pub date: NaiveDate,
pub tags: Vec<String>,
pub summary: String,
pub slug: String,
pub body_html: String,
}
#[derive(Serialize)]
pub struct Document {
pub title: String,
pub site_title: String,
pub description: String,
pub social_meta: String,
pub header_title: String,
pub header_tagline: String,
pub year: String,
pub css_href: String,
pub home_href: String,
pub archive_href: String,
pub tags_href: String,
pub about_href: String,
pub feed_href: String,
pub active_nav: String,
pub posts: Vec<PostView>,
pub post: Option<PostView>,
pub prev_post: Option<PostView>,
pub next_post: Option<PostView>,
pub sidebar: SidebarView,
pub tags: Vec<TagView>,
pub tag: Option<TagView>,
}
#[derive(Serialize)]
pub struct PostView {
pub title: String,
pub summary: String,
pub href: String,
pub date_long: String,
pub date_short: String,
pub read_time: String,
pub tags: Vec<TagView>,
pub body_html: String,
}
#[derive(Serialize)]
pub struct TagView {
pub name: String,
pub href: String,
pub count: usize,
}
#[derive(Serialize)]
pub struct SidebarView {
pub older_count: usize,
pub essays: Vec<PostView>,
pub tags: Vec<TagView>,
pub archive_href: String,
}
#[derive(Serialize)]
pub struct SiteView {
pub title: String,
pub tagline: String,
pub header_title: String,
pub header_tagline: String,
}
impl From<&Document> for SiteView {
fn from(doc: &Document) -> Self {
Self {
title: doc.site_title.clone(),
tagline: doc.description.clone(),
header_title: doc.header_title.clone(),
header_tagline: doc.header_tagline.clone(),
}
}
}