diff --git a/src/lib.rs b/src/lib.rs index bce90ac..a6ba06d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ use std::{ use anyhow::Context; use serde::Deserialize; +use serving::get_name; use url::Url; use walkdir::WalkDir; @@ -100,14 +101,11 @@ impl Site { if let Some(ext) = path.extension() { if ext == "hbs" && entry.file_type().is_file() { - template_index.insert( + let (_, name) = get_name( path.strip_prefix(&templates_path) - .context("This really shouldn't have happened")? - .with_extension("") - .to_string_lossy() - .to_string(), - path.to_owned(), + .context("This really shouldn't have happened")?, ); + template_index.insert(name, path.to_owned()); } } } diff --git a/src/serving.rs b/src/serving.rs index f6e1fb9..8563742 100644 --- a/src/serving.rs +++ b/src/serving.rs @@ -27,9 +27,12 @@ fn with_build_path( } /// Helper to get the "name" of a path. -fn get_name(path: &Path) -> (PathBuf, String) { +pub fn get_name(path: &Path) -> (PathBuf, String) { let name = path.with_extension(""); - let name_str = name.display().to_string(); + let name_str = name + .display() + .to_string() + .replace(std::path::MAIN_SEPARATOR, "/"); (name, name_str) }