mirror of
https://github.com/kbenestad/mdcms.git
synced 2026-06-18 07:24:31 +00:00
Pages whose filename matches a nav section-id now get a clean pathname
URL (e.g. /timesheet) instead of the hash-based /#pages/timesheet.md.
- _initialPathname captured at IIFE start; handles ?_route= from 404.html
- basePath determined by initBasePath() after nav data loads; subpath
deployments (e.g. /mysite/) handled automatically
- navigateTo() uses replaceState to /slug for section-id pages and falls
back to #hash for everything else
- popstate listener handles browser history if a clean URL was the entry
- resolveSlugToFile() validates that slug is both a section code and has
a pages/{slug}.md entry in navData
- app/404.html added for GitHub Pages SPA routing
https://claude.ai/code/session_01Ai8xRvmrzdhuTKiRQ2fnn9
30 lines
1 KiB
HTML
30 lines
1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Redirecting…</title>
|
|
<script>
|
|
// SPA routing for GitHub Pages: the server returns this 404 page for any path
|
|
// it can't resolve. We encode the intended path as ?_route= and redirect to the
|
|
// app root so index.html can pick it up and render the right page.
|
|
(function () {
|
|
var path = window.location.pathname;
|
|
var search = window.location.search;
|
|
var hash = window.location.hash;
|
|
|
|
// On GitHub Pages project sites the app lives at /repo-name/, so we keep
|
|
// that prefix and only encode the segment after it.
|
|
var parts = path.split('/');
|
|
var isGhPages = window.location.hostname.endsWith('.github.io') && parts.length > 2;
|
|
var base = isGhPages ? '/' + parts[1] + '/' : '/';
|
|
var route = '/' + parts.slice(isGhPages ? 2 : 1).join('/');
|
|
|
|
var qs = '_route=' + encodeURIComponent(route);
|
|
if (search) qs += '&' + search.slice(1);
|
|
|
|
window.location.replace(window.location.origin + base + '?' + qs + hash);
|
|
})();
|
|
</script>
|
|
</head>
|
|
<body></body>
|
|
</html>
|