feat(404): try redirect to lowercase URL
This commit is contained in:
@@ -11,6 +11,44 @@ const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => {
|
|||||||
<h1>404</h1>
|
<h1>404</h1>
|
||||||
<p>{i18n(cfg.locale).pages.error.notFound}</p>
|
<p>{i18n(cfg.locale).pages.error.notFound}</p>
|
||||||
<a href={baseDir}>{i18n(cfg.locale).pages.error.home}</a>
|
<a href={baseDir}>{i18n(cfg.locale).pages.error.home}</a>
|
||||||
|
<script
|
||||||
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: `
|
||||||
|
if (typeof fetchData !== "undefined") {
|
||||||
|
fetchData.then(function(index) {
|
||||||
|
var base = document.querySelector("base");
|
||||||
|
var basePath = (base && base.getAttribute("href")) || "/";
|
||||||
|
if (basePath.length > 1 && basePath.endsWith("/")) {
|
||||||
|
basePath = basePath.slice(0, -1);
|
||||||
|
}
|
||||||
|
var pathname = window.location.pathname;
|
||||||
|
if (basePath.length > 1 && pathname.startsWith(basePath)) {
|
||||||
|
pathname = pathname.slice(basePath.length);
|
||||||
|
}
|
||||||
|
if (pathname.startsWith("/")) {
|
||||||
|
pathname = pathname.slice(1);
|
||||||
|
}
|
||||||
|
if (pathname.endsWith("/")) {
|
||||||
|
pathname = pathname.slice(0, -1);
|
||||||
|
}
|
||||||
|
// Strip .html extension if present
|
||||||
|
if (pathname.endsWith(".html")) {
|
||||||
|
pathname = pathname.slice(0, -5);
|
||||||
|
}
|
||||||
|
// Convert trailing /index to folder slug
|
||||||
|
if (pathname.endsWith("/index")) {
|
||||||
|
pathname = pathname.slice(0, -6);
|
||||||
|
}
|
||||||
|
var lowered = pathname.toLowerCase();
|
||||||
|
if (lowered !== pathname && index[lowered] != null) {
|
||||||
|
var target = basePath + (basePath.endsWith("/") ? "" : "/") + lowered;
|
||||||
|
window.location.replace(target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</article>
|
</article>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user