diff options
| author | Danilo M. <danix@danix.xyz> | 2026-04-17 11:54:12 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-04-17 11:54:12 +0200 |
| commit | a9ae07aea8ab7d9e9b3440bcb90de2ac8163f55e (patch) | |
| tree | c3a0dde60f6bad8a6272467ab53fd5d9e71072c1 /themes | |
| parent | 1ae60588c0ceb8a3ec0b35f4c2cb45a2116ec89a (diff) | |
| download | danixxyz-a9ae07aea8ab7d9e9b3440bcb90de2ac8163f55e.tar.gz danixxyz-a9ae07aea8ab7d9e9b3440bcb90de2ac8163f55e.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'themes')
| -rw-r--r-- | themes/danix-xyz-hacker/assets/js/not-found-page.js | 34 | ||||
| -rw-r--r-- | themes/danix-xyz-hacker/layouts/404.html | 6 |
2 files changed, 26 insertions, 14 deletions
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 = [ <!-- Navigation Links --> <div class="space-y-4 flex flex-col items-center mb-12" x-data="notFoundNav()"> - <a :href="homeLink" class="btn btn-primary"> + <a :href="homeLink" @click.prevent="goHome()" class="btn btn-primary"> {{ i18n "goHome" }} </a> - <a :href="articlesLink" class="btn btn-secondary"> + <a :href="articlesLink" @click.prevent="goArticles()" class="btn btn-secondary"> {{ i18n "browseArticles" }} </a> - <a :href="contactLink" class="btn btn-outline"> + <a :href="contactLink" @click.prevent="goContact()" class="btn btn-outline"> {{ i18n "contactSupport" }} </a> </div> |
