add: recursive flag

This commit is contained in:
andrew 2026-04-23 14:43:52 -04:00
parent 5b2c3e969c
commit c798e387bd
2 changed files with 31 additions and 2 deletions

View file

@ -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<PathBuf>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
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(())
}

View file

@ -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<PathBuf>,
#[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);
}