From: Danilo M. Date: Fri, 17 Apr 2026 09:54:12 +0000 (+0200) Subject: fix: use client-side language detection with redirect rules for 404 navigation X-Git-Tag: release_22042026-1342~133 X-Git-Url: https://git.danix.xyz/?a=commitdiff_plain;h=a9ae07aea8ab7d9e9b3440bcb90de2ac8163f55e;p=danix.xyz-2.git fix: use client-side language detection with redirect rules for 404 navigation Rely on hugo.toml redirect rules to serve correct 404.html and detect language from window.location.pathname in notFoundNav() Alpine component. Navigation links now properly route to Italian (/it/*) or English (/*) sections based on request URL. Co-Authored-By: Claude Haiku 4.5 --- diff --git a/hugo.toml b/hugo.toml index f5019c0..4913f63 100644 --- a/hugo.toml +++ b/hugo.toml @@ -124,3 +124,13 @@ enableRobotsTXT = true label = "Tech" color_dark = "#a855f7" color_light = "#7c3aed" + +[[redirects]] + from = '/it/**' + to = '/it/404.html' + status = 404 + +[[redirects]] # Default language should be last. + from = '/**' + to = '/404.html' + status = 404 \ No newline at end of file diff --git a/themes/danix-xyz-hacker/assets/js/not-found-page.js b/themes/danix-xyz-hacker/assets/js/not-found-page.js index 78e3591..cec60bd 100644 --- a/themes/danix-xyz-hacker/assets/js/not-found-page.js +++ b/themes/danix-xyz-hacker/assets/js/not-found-page.js @@ -31,17 +31,29 @@ document.addEventListener('alpine:init', () => { } })); - Alpine.data('notFoundNav', () => ({ - get homeLink() { - return window.currentLang === 'it' ? '/it/' : '/'; - }, - get articlesLink() { - return window.currentLang === 'it' ? '/it/articles/' : '/articles/'; - }, - get contactLink() { - return window.currentLang === 'it' ? '/it/is/here/' : '/is/here/'; - } - })); + Alpine.data('notFoundNav', () => { + const isItalian = window.location.pathname.startsWith('/it/'); + return { + get homeLink() { + return isItalian ? '/it/' : '/'; + }, + get articlesLink() { + return isItalian ? '/it/articles/' : '/articles/'; + }, + get contactLink() { + return isItalian ? '/it/is/here/' : '/is/here/'; + }, + goHome() { + window.location.href = this.homeLink; + }, + goArticles() { + window.location.href = this.articlesLink; + }, + goContact() { + window.location.href = this.contactLink; + } + }; + }); console.log('notFoundPage Alpine component registered'); }); diff --git a/themes/danix-xyz-hacker/layouts/404.html b/themes/danix-xyz-hacker/layouts/404.html index 0fb6c9a..341f90b 100644 --- a/themes/danix-xyz-hacker/layouts/404.html +++ b/themes/danix-xyz-hacker/layouts/404.html @@ -82,13 +82,13 @@ window.articlesData = [