2024-11-27 18:46:10 +01:00
|
|
|
use core::fmt;
|
|
|
|
|
2024-11-29 20:03:32 +01:00
|
|
|
use super::{Dir, Query, VPath};
|
2024-11-27 18:46:10 +01:00
|
|
|
|
2025-07-10 16:50:41 +02:00
|
|
|
/// This Dir exists to serve as a compatibility layer for very old links that end with .html.
|
2024-11-27 18:46:10 +01:00
|
|
|
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,
|
|
|
|
{
|
2024-11-29 20:03:32 +01:00
|
|
|
fn query(&self, path: &VPath, query: &mut Query) {
|
2024-11-27 18:46:10 +01:00
|
|
|
let mut path = path.to_owned();
|
|
|
|
if path.extension() == Some("html") {
|
|
|
|
path.set_extension("");
|
|
|
|
}
|
|
|
|
|
2024-11-29 20:03:32 +01:00
|
|
|
self.inner.query(&path, query);
|
2024-11-27 18:46:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|