add: recursive flag
This commit is contained in:
parent
5b2c3e969c
commit
c798e387bd
2 changed files with 31 additions and 2 deletions
20
src/lib.rs
20
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<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(())
|
||||||
|
}
|
||||||
|
|
|
||||||
13
src/main.rs
13
src/main.rs
|
|
@ -2,7 +2,7 @@ use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use typssg::compile_article;
|
use typssg::{compile_article, compile_all};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
|
@ -11,6 +11,9 @@ struct Args {
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
prepend: Option<PathBuf>,
|
prepend: Option<PathBuf>,
|
||||||
|
|
||||||
|
#[arg(short)]
|
||||||
|
recursive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
@ -21,7 +24,13 @@ fn main() {
|
||||||
|
|
||||||
let args = Args::parse();
|
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}");
|
eprintln!("{e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue