adding document mode

I've been thinking a lot about the treehouse and I feel like it's time to say goodbye to the tree format.
This commit is contained in:
りき萌 2025-07-10 16:50:41 +02:00
parent 550c062327
commit 36705e7c1e
31 changed files with 940 additions and 409 deletions

View file

@ -1,5 +1,6 @@
mod atom;
mod dir_helper;
mod doc;
mod include_static_helper;
mod simple_template;
mod tree;
@ -7,6 +8,7 @@ mod tree;
use std::{ops::ControlFlow, sync::Arc};
use atom::FeedDir;
use chrono::{DateTime, Utc};
use dir_helper::DirHelper;
use handlebars::{handlebars_helper, Handlebars};
use include_static_helper::IncludeStaticHelper;
@ -18,13 +20,14 @@ use crate::{
dirs::Dirs,
fun::seasons::Season,
generate::{
doc::DocDir,
simple_template::SimpleTemplateDir,
tree::{DirIndex, TreehouseDir},
},
sources::Sources,
vfs::{
self, layered_dir, AnchoredAtExt, Cd, Content, ContentCache, Dir, DynDir, Entries,
HtmlCanonicalize, MemDir, Overlay, ToDynDir, VPath, VPathBuf,
self, layered_dir, AnchoredAtExt, Cd, Content, ContentCache, Dir, DynDir, HtmlCanonicalize,
MemDir, ToDynDir, VPath, VPathBuf,
},
};
@ -54,8 +57,10 @@ fn create_handlebars(site: &str, static_: DynDir) -> Handlebars<'static> {
let mut handlebars = Handlebars::new();
handlebars_helper!(cat: |a: String, b: String| a + &b);
handlebars_helper!(iso_date: |d: DateTime<Utc>| d.format("%F").to_string());
handlebars.register_helper("cat", Box::new(cat));
handlebars.register_helper("iso_date", Box::new(iso_date));
handlebars.register_helper("asset", Box::new(DirHelper::new(site, static_.clone())));
handlebars.register_helper(
"include_static",
@ -103,7 +108,13 @@ pub fn target(dirs: Arc<Dirs>, sources: Arc<Sources>) -> DynDir {
let dir_index = DirIndex::new(sources.treehouse.files_by_tree_path.keys().map(|x| &**x));
let treehouse_dir = layered_dir(&[
TreehouseDir::new(dirs, sources.clone(), handlebars.clone(), dir_index).to_dyn(),
TreehouseDir::new(dirs.clone(), sources.clone(), handlebars.clone(), dir_index).to_dyn(),
DocDir {
sources: sources.clone(),
dirs,
handlebars: handlebars.clone(),
}
.to_dyn(),
SimpleTemplateDir::new(sources.clone(), handlebars.clone()).to_dyn(),
]);