diff --git a/src/lib.rs b/src/lib.rs index a03e23d..efb7942 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -170,3 +170,23 @@ fn parse_outline(elem: &mut HtmlElement, outline: &mut EcoString, curr_level: &m } } } + +pub fn compile_all( + root_dir: &PathBuf, + prepend: &Option, +) -> Result<(), Box> { + for entry in fs::read_dir(root_dir)? { + let entry = entry?; + let path = entry.path(); + + if path.is_dir() { + compile_all(&path, prepend)?; + } else if path.file_name().is_some_and(|n| n == "index.typ") { + let dir = path.parent().unwrap().to_path_buf(); + println!("compiling {}", dir.display()); + compile_article(&dir, prepend)?; + } + } + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index b836b3f..4e5ce4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::env; use std::path::PathBuf; use clap::Parser; -use typssg::compile_article; +use typssg::{compile_article, compile_all}; #[derive(Parser)] struct Args { @@ -11,6 +11,9 @@ struct Args { #[arg(long)] prepend: Option, + + #[arg(short)] + recursive: bool, } fn main() { @@ -21,7 +24,13 @@ fn main() { let args = Args::parse(); - if let Err(e) = compile_article(&args.dir, &args.prepend) { + let result = if args.recursive { + compile_all(&args.dir, &args.prepend) + } else { + compile_article(&args.dir, &args.prepend) + }; + + if let Err(e) = result { eprintln!("{e}"); std::process::exit(1); }