fix building the site on windows

This commit is contained in:
zyl 2024-06-14 13:25:23 -07:00
parent ecf408d796
commit e770a9bd8d
No known key found for this signature in database
GPG key ID: FDAEE0976A45AAC3
2 changed files with 9 additions and 8 deletions

View file

@ -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());
}
}
}

View file

@ -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)
}