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:
hypercross 2026-07-14 15:56:38 +08:00
parent a934901cce
commit 8c9506c106
1 changed files with 8 additions and 3 deletions

View File

@ -109,9 +109,14 @@ export const Article: Component<ArticleProps & ParentProps> = (props) => {
e.preventDefault();
// Resolve relative hrefs against the current page path so that
// e.g. "blah.md" on /content/page.md becomes /content/blah.md
const resolved = new URL(href, window.location.origin + window.location.pathname).pathname;
navigate(resolved);
// e.g. "blah.md" on /content/page.md becomes /content/blah
const resolved = new URL(href, window.location.origin + window.location.pathname);
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);