spike(spa-mini): legacy-hugo-urls auf kurze form normalisieren
/YYYY/MM/DD/<dtag>.html/ wird erkannt, via history.replaceState auf die kanonische Form /<dtag>/ umgeschrieben, dann der Post geladen. Externe Backlinks auf alte Hugo-URLs landen damit ohne Reload-Flash auf der neuen kurzen Adresse. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fc6e0fecdb
commit
1147980f2a
|
|
@ -587,15 +587,36 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Erkennt Legacy-Hugo-URL /YYYY/MM/DD/<dtag>.html oder .../<dtag>.html/
|
||||||
|
// Returns <dtag> oder null.
|
||||||
|
function parseLegacyUrl(path) {
|
||||||
|
const m = path.match(/^\d{4}\/\d{2}\/\d{2}\/([^/]+?)\.html\/?$/);
|
||||||
|
return m ? decodeURIComponent(m[1]) : null;
|
||||||
|
}
|
||||||
|
|
||||||
function route() {
|
function route() {
|
||||||
// Pfad: "" oder "/" → Liste; "/<dtag>" oder "/<dtag>/" → Einzelpost
|
// Pfad normalisieren: Slashes, "index.html"
|
||||||
const path = location.pathname.replace(/^\/+|\/+$/g, '');
|
const path = location.pathname.replace(/^\/+|\/+$/g, '');
|
||||||
|
|
||||||
|
// Leer → Liste
|
||||||
if (path === '' || path === 'index.html') {
|
if (path === '' || path === 'index.html') {
|
||||||
loadList();
|
loadList();
|
||||||
} else {
|
window.scrollTo(0, 0);
|
||||||
const dtag = decodeURIComponent(path.split('/')[0]);
|
return;
|
||||||
loadPost(dtag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Legacy-Form YYYY/MM/DD/<dtag>.html/ → auf kurze Form umschreiben
|
||||||
|
const legacyDtag = parseLegacyUrl(path);
|
||||||
|
if (legacyDtag) {
|
||||||
|
history.replaceState(null, '', `/${encodeURIComponent(legacyDtag)}/`);
|
||||||
|
loadPost(legacyDtag);
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kanonische kurze Form /<dtag>/ → Post laden
|
||||||
|
const dtag = decodeURIComponent(path.split('/')[0]);
|
||||||
|
loadPost(dtag);
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue