From 1147980f2a24b165490083a1c065dd6cfae24078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lohrer?= Date: Wed, 15 Apr 2026 14:44:25 +0200 Subject: [PATCH] spike(spa-mini): legacy-hugo-urls auf kurze form normalisieren /YYYY/MM/DD/.html/ wird erkannt, via history.replaceState auf die kanonische Form // 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) --- preview/spa-mini/index.html | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/preview/spa-mini/index.html b/preview/spa-mini/index.html index da69f2a..195a49d 100644 --- a/preview/spa-mini/index.html +++ b/preview/spa-mini/index.html @@ -587,15 +587,36 @@ }); } + // Erkennt Legacy-Hugo-URL /YYYY/MM/DD/.html oder .../.html/ + // Returns oder null. + function parseLegacyUrl(path) { + const m = path.match(/^\d{4}\/\d{2}\/\d{2}\/([^/]+?)\.html\/?$/); + return m ? decodeURIComponent(m[1]) : null; + } + function route() { - // Pfad: "" oder "/" → Liste; "/" oder "//" → Einzelpost + // Pfad normalisieren: Slashes, "index.html" const path = location.pathname.replace(/^\/+|\/+$/g, ''); + + // Leer → Liste if (path === '' || path === 'index.html') { loadList(); - } else { - const dtag = decodeURIComponent(path.split('/')[0]); - loadPost(dtag); + window.scrollTo(0, 0); + return; } + + // Legacy-Form YYYY/MM/DD/.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 // → Post laden + const dtag = decodeURIComponent(path.split('/')[0]); + loadPost(dtag); window.scrollTo(0, 0); }