diff --git a/src/main.rs b/src/main.rs index 80efdbd..34be3ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,10 @@ use toml::Table; use glob::glob; use roxy_core::roxy::{Parser, Roxy}; -use crate::{iter_ext::{MapFoldExt, Head}, result_ext::FilterExt}; +use crate::{ + iter_ext::{Head, MapFoldExt}, + result_ext::FilterExt, +}; const DEFAULT_THEME: &'static str = "base16-ocean.dark"; const CONTENT_EXT: [&'static str; 4] = ["md", "tera", "html", "htm"]; @@ -98,6 +101,15 @@ fn load_config(path: &Path) -> Config { .into() } +fn as_formatted_path>(path: &P) -> Option { + let path = path.as_ref(); + if path.with_extension("").file_name()? == "index" { + Some(path.with_file_name("")) + } else { + Some(path.with_extension("")) + } +} + fn context_from_meta_files<'a, T: AsRef>( files: &Vec<&PathBuf>, file_path: &'a FilePath, @@ -115,12 +127,12 @@ fn context_from_meta_files<'a, T: AsRef>( let path = file_path.strip_root(path)?; context.insert(&path, &tera::to_value(toml).map_err(handle_err)?); - let path = path.with_file_name(""); - - if let Some(slug) = file_path.as_slug(&path) { - let slug = PathBuf::from("/").join(slug); - if let Ok(slug) = to_value(slug) { - context.insert(&path.join("path"), &slug); + if let Some(path) = as_formatted_path(&path) { + if let Some(slug) = file_path.as_slug(&path) { + let slug = PathBuf::from("/").join(slug); + if let Ok(slug) = to_value(slug) { + context.insert(&path.join("path"), &slug); + } } } } @@ -206,7 +218,6 @@ fn main() -> Result<(), Box> { html.add_context(&ctx); parser.push(&mut html); - //println!("{output_path:?}"); Roxy::process_file(&file, &output_path, &mut parser).unwrap(); }