1use std::collections::{HashMap, HashSet};
2use std::path::PathBuf;
3use std::sync::{Arc, Mutex};
4
5pub struct AssetPipeline {
6 pub assets_dir: PathBuf,
7 pub base_url: String,
8 pub name_template: String,
9 pub map: Arc<Mutex<HashMap<String, String>>>,
10}
11
12impl AssetPipeline {
13 pub fn new(assets_dir: PathBuf, base_url: String) -> Self {
14 Self {
15 assets_dir,
16 base_url,
17 name_template: "[name]-[hash:8].[ext]".into(),
18 map: Arc::new(Mutex::new(HashMap::new())),
19 }
20 }
21}
22
23pub struct Ctx {
24 pub file_path: PathBuf,
25 pub root: PathBuf,
26 pub body: String,
27 pub html: Option<String>,
28 pub mdx_body: Option<String>,
29 pub toc: Option<serde_json::Value>,
30 pub plain_text: Option<String>,
31 pub unique_cache: Mutex<HashSet<String>>,
32 pub assets: Option<AssetPipeline>,
33}
34
35impl Ctx {
36 pub fn new(file_path: PathBuf, root: PathBuf, body: String) -> Self {
37 Self {
38 file_path,
39 root,
40 body,
41 html: None,
42 mdx_body: None,
43 toc: None,
44 plain_text: None,
45 unique_cache: Mutex::new(HashSet::new()),
46 assets: None,
47 }
48 }
49
50 pub fn empty() -> Self {
51 Self::new(PathBuf::new(), PathBuf::new(), String::new())
52 }
53}