org-static/src/article.rs

37 lines
762 B
Rust
Raw Normal View History

2022-12-23 06:23:45 +00:00
use serde::Serialize;
2022-12-25 06:57:01 +00:00
use std::{collections::HashSet, path::PathBuf};
2022-12-23 06:23:45 +00:00
2022-12-25 06:57:01 +00:00
use crate::config::Config;
#[derive(Serialize, Default, Clone)]
2022-12-23 06:23:45 +00:00
pub struct Article {
2022-12-25 06:57:01 +00:00
pub title: String,
pub date: String,
pub author: String,
pub slug: String,
pub file_path: PathBuf,
pub tags: HashSet<String>,
}
impl Article {
pub fn get_build_path(&self, config: &Config) -> PathBuf {
config
.get_build_path()
.join("articles")
.join(&self.slug)
.join("index.html")
}
2022-12-23 06:23:45 +00:00
}
#[derive(Serialize, Default)]
pub struct ArticleContext {
article: Article,
content: String,
}
impl ArticleContext {
2022-12-25 06:57:01 +00:00
pub fn new(article: Article, content: String) -> Self {
Self { article, content }
2022-12-23 06:51:56 +00:00
}
2022-12-23 06:23:45 +00:00
}