treehouse/src/vfs/html_canonicalize.rs
リキ萌 550c062327 factor out simple templates into a separate SimpleTemplateDir
there's no need to bloat TreehouseDir with that logic
2025-07-10 20:34:56 +02:00

37 lines
780 B
Rust

use core::fmt;
use super::{Dir, Query, VPath};
/// This Dir exists to serve as a compatibility layer for very old links that end with .html.
pub struct HtmlCanonicalize<T> {
inner: T,
}
impl<T> HtmlCanonicalize<T> {
pub fn new(inner: T) -> Self {
Self { inner }
}
}
impl<T> Dir for HtmlCanonicalize<T>
where
T: Dir,
{
fn query(&self, path: &VPath, query: &mut Query) {
let mut path = path.to_owned();
if path.extension() == Some("html") {
path.set_extension("");
}
self.inner.query(&path, query);
}
}
impl<T> fmt::Debug for HtmlCanonicalize<T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "HtmlCanonicalize({:?})", self.inner)
}
}