Apply some optimizations

This commit is contained in:
Nat 2023-08-29 09:23:25 -07:00
parent b2e17324a3
commit f9f1a16e01
Signed by: nat
GPG Key ID: B53AB05285D710D6
1 changed files with 15 additions and 15 deletions

View File

@ -20,7 +20,7 @@ struct Frontmatter {
}
// The struct representing the page, as constructed from the frontmatter
#[derive(Clone, Serialize)]
#[derive(Serialize)]
struct Page {
title: String,
permalink: String,
@ -111,10 +111,21 @@ fn main() {
}
};
let liquid_parser = liquid::ParserBuilder::with_stdlib()
.build().expect("calathea: failed to build liquid parser");
let liquid_template = match liquid_parser.parse(template.as_str()) {
Ok(t) => t,
Err(e) => {
println!("calathea: failed to parse template '{}': {}", template_path.display(), e);
process::exit(1);
}
};
let mut page_map: HashMap<String, Page> = HashMap::new();
let mut content_map: HashMap<String, String> = HashMap::new();
let mut incoming_map: HashMap<String, Vec<Page>> = HashMap::new();
let mut incoming_map: HashMap<String, Vec<&Page>> = HashMap::new();
// Pull the source files into memory
let src_paths = match fs::read_dir(src_dir) {
@ -207,7 +218,7 @@ fn main() {
let incoming_pages = incoming_map.get_mut(&name).unwrap();
incoming_pages.push(page.clone());
incoming_pages.push(page);
}
content_map.insert(page.title.clone(), link_re.replace_all(original_content.as_str(), |caps: &Captures| {
@ -231,19 +242,8 @@ fn main() {
md_options.extension.footnotes = true;
md_options.extension.front_matter_delimiter = Some("---".to_owned());
let liquid_parser = liquid::ParserBuilder::with_stdlib()
.build().expect("calathea: failed to build liquid parser");
let liquid_template = match liquid_parser.parse(template.as_str()) {
Ok(t) => t,
Err(e) => {
println!("calathea: failed to parse template '{}': {}", template_path.display(), e);
process::exit(1);
}
};
for page in page_map.values() {
let incoming_pages: &Vec<Page> = incoming_map.get(&page.title).unwrap();
let incoming_pages = incoming_map.get(&page.title).unwrap();
let content = content_map.get(&page.title).unwrap();
let globals = liquid::object!({