Fix render command.

This commit is contained in:
2025-07-05 13:59:31 -05:00
parent 4de2b399f5
commit deee0e8d29
2 changed files with 22 additions and 5 deletions

View File

@@ -105,9 +105,14 @@ impl Historian {
if entry_metadata.is_file() && !child.ends_with(MD_EXTENSION) { if entry_metadata.is_file() && !child.ends_with(MD_EXTENSION) {
attachments.push(child); attachments.push(child);
} else if !(child.starts_with(".") || child == self.index_filename || child == DEFAULT_TOML_FILENAME) { } else if !(child.starts_with(".") || child == self.index_filename || child == DEFAULT_TOML_FILENAME) {
let mut full_name = format!("{}/{}", name, child);
if full_name.starts_with('/') {
full_name.remove(0);
}
children.push(Child { children.push(Child {
name: child.to_owned(), name: child.to_owned(),
full_name: format!("{}/{}", name, child), full_name: full_name,
title: if entry_metadata.is_file() { title: if entry_metadata.is_file() {
entry_path.file_stem().unwrap().to_str().unwrap().to_owned() entry_path.file_stem().unwrap().to_str().unwrap().to_owned()
} else { } else {
@@ -543,11 +548,12 @@ fn export_resource(resource_path: PathBuf, output_path: &str) {
let mut resource_output_path: PathBuf = output_path.into(); let mut resource_output_path: PathBuf = output_path.into();
let resource_name = resource_path.file_name().unwrap().to_str().unwrap(); let resource_name = resource_path.file_name().unwrap().to_str().unwrap();
resource_output_path.push(&resource_name); resource_output_path.push(&resource_name);
println!("export resource {} to {:?}", resource_name, resource_output_path); println!("export resource {} from {:?} to {:?}", resource_name, resource_path, resource_output_path);
fs::copy(resource_path, resource_output_path).unwrap(); fs::copy(resource_path, resource_output_path).unwrap();
} }
fn export_wiki_page(historian: &Historian, renderer: &PageRenderer, name: &str, output_path: &str) { fn export_wiki_page(historian: &Historian, renderer: &PageRenderer, name: &str, output_path: &str) {
println!("resolve page {} {:?}", name, historian.resolve_to_page(name).is_some());
if let Some(page) = historian.resolve_to_page(name) { if let Some(page) = historian.resolve_to_page(name) {
let page_path: PathBuf = page.full_name.to_owned().replace(".md", ".html").into(); let page_path: PathBuf = page.full_name.to_owned().replace(".md", ".html").into();
let mut page_output_path: PathBuf = output_path.into(); let mut page_output_path: PathBuf = output_path.into();
@@ -570,12 +576,13 @@ fn export_wiki_page(historian: &Historian, renderer: &PageRenderer, name: &str,
page_html_file.write_all(page_html.as_bytes()); page_html_file.write_all(page_html.as_bytes());
for attachment in page.attachments { for attachment in page.attachments {
let attachment_path = page_path.join(attachment); let attachment_path = page.path.parent().unwrap().join(attachment);
export_resource(attachment_path, page_output_path.to_str().unwrap()); export_resource(attachment_path, page_output_path.to_str().unwrap());
} }
for child in page.children { for child in page.children {
export_wiki_page(historian, renderer, child.path.to_str().unwrap(), output_path); println!("child {} {} {:?} {:?}", child.full_name, child.name, child.path, output_path);
export_wiki_page(historian, renderer, &child.full_name, output_path);
} }
} }
} }
@@ -589,7 +596,7 @@ impl<'a> Linker<'a> {
pub fn new(historian: &Historian) -> Linker { pub fn new(historian: &Historian) -> Linker {
Linker { Linker {
historian, historian,
link_regex: Regex::new(r"\[\[(?<link>[\w\s]+)(?:\|(?<label>[\w\s]+))?\]\]").unwrap() link_regex: Regex::new(r"\[\[(?<link>[\w\s\-]+)(?:\|(?<label>[\w\s\-]+))?\]\]").unwrap()
} }
} }

View File

@@ -190,12 +190,22 @@ struct Args {
template_path: Option<String> template_path: Option<String>
} }
fn print_tree(historian: &Historian, page: &Page, prefix: &str) {
for child in &page.children {
if let Some(child_page) = historian.resolve_to_page(&child.full_name) {
println!("{}{}", prefix, child_page.full_name);
print_tree(historian, &child_page, &format!("{}{}", prefix, prefix));
}
}
}
#[rocket::main] #[rocket::main]
async fn main() { async fn main() {
let args = Args::parse(); let args = Args::parse();
if let Some(wiki_path) = args.wiki_path { if let Some(wiki_path) = args.wiki_path {
let historian = Historian::new(wiki_path); let historian = Historian::new(wiki_path);
print_tree(&historian, &historian.resolve_to_page("").unwrap(), "*");
let renderer = if let Some(template_path) = args.template_path { let renderer = if let Some(template_path) = args.template_path {
PageRenderer::with_template_path(&template_path) PageRenderer::with_template_path(&template_path)