add paths to non-subdir pages

This commit is contained in:
KitsuneCafe 2024-02-17 06:40:58 -05:00
parent 4ad7bf5786
commit 696bfa0afe

View file

@ -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<P: AsRef<Path>>(path: &P) -> Option<PathBuf> {
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<Path>>(
files: &Vec<&PathBuf>,
file_path: &'a FilePath<T>,
@ -115,12 +127,12 @@ fn context_from_meta_files<'a, T: AsRef<Path>>(
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<dyn std::error::Error>> {
html.add_context(&ctx);
parser.push(&mut html);
//println!("{output_path:?}");
Roxy::process_file(&file, &output_path, &mut parser).unwrap();
}