fix: strip .md extension from resolved article paths
Ensures that navigation to markdown files strips the extension, allowing the SPA fallback to handle refreshes instead of requesting the raw file.
This commit is contained in:
parent
a934901cce
commit
8c9506c106
|
|
@ -109,9 +109,14 @@ export const Article: Component<ArticleProps & ParentProps> = (props) => {
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// Resolve relative hrefs against the current page path so that
|
// Resolve relative hrefs against the current page path so that
|
||||||
// e.g. "blah.md" on /content/page.md becomes /content/blah.md
|
// e.g. "blah.md" on /content/page.md becomes /content/blah
|
||||||
const resolved = new URL(href, window.location.origin + window.location.pathname).pathname;
|
const resolved = new URL(href, window.location.origin + window.location.pathname);
|
||||||
navigate(resolved);
|
let pathname = resolved.pathname;
|
||||||
|
// Strip .md extension so refreshes hit the SPA fallback, not the raw file
|
||||||
|
if (pathname.endsWith(".md")) {
|
||||||
|
pathname = pathname.slice(0, -3);
|
||||||
|
}
|
||||||
|
navigate(pathname + resolved.hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
dom.addEventListener("click", onClick);
|
dom.addEventListener("click", onClick);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue