]> danix's work - danix.xyz-2.git/commitdiff
fix: use Hugo content-based 404 pages for proper multilingual support
authorDanilo M. <redacted>
Fri, 17 Apr 2026 09:49:24 +0000 (11:49 +0200)
committerDanilo M. <redacted>
Fri, 17 Apr 2026 09:49:24 +0000 (11:49 +0200)
Created language-specific 404 pages (content/en/404.md and content/it/404.md)
instead of using JavaScript detection. Hugo now properly routes 404 errors to
the correct language context, allowing .Lang and i18n to work correctly.
Removed JS language detection hack.

Co-Authored-By: Claude Haiku 4.5 <redacted>
content/en/404.md [new file with mode: 0644]
content/it/404.md [new file with mode: 0644]
themes/danix-xyz-hacker/assets/js/not-found-page.js
themes/danix-xyz-hacker/layouts/404.html

diff --git a/content/en/404.md b/content/en/404.md
new file mode 100644 (file)
index 0000000..6e619f2
--- /dev/null
@@ -0,0 +1,5 @@
+---
+title: "404 Not Found"
+outputs:
+  - html
+---
diff --git a/content/it/404.md b/content/it/404.md
new file mode 100644 (file)
index 0000000..6e619f2
--- /dev/null
@@ -0,0 +1,5 @@
+---
+title: "404 Not Found"
+outputs:
+  - html
+---
index 78e35911352e3aa55601c41b58b9061f6ce54e2d..6ec8895ed0ea3f023e9fb48814d578bb23d2185a 100644 (file)
@@ -31,17 +31,5 @@ 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/';
-    }
-  }));
-
   console.log('notFoundPage Alpine component registered');
 });
index 0fb6c9a6ed213a17c2bb736da615b3eb4180b708..a81f34d228ba324bb90690cc6d8f11ef0784bac9 100644 (file)
@@ -1,10 +1,5 @@
 {{ define "main" }}
 
-<!-- Detect language from current URL -->
-<script>
-window.currentLang = window.location.pathname.startsWith('/it/') ? 'it' : 'en';
-</script>
-
 <!-- Pass articles data to JavaScript for Alpine.js -->
 <script>
 window.articlesData = [
@@ -81,14 +76,18 @@ window.articlesData = [
     </div>
 
     <!-- Navigation Links -->
-    <div class="space-y-4 flex flex-col items-center mb-12" x-data="notFoundNav()">
-      <a :href="homeLink" class="btn btn-primary">
+    <div class="space-y-4 flex flex-col items-center mb-12">
+      {{ $homeLink := "/" }}
+      {{ if eq .Lang "it" }}
+        {{ $homeLink = "/it/" }}
+      {{ end }}
+      <a href="{{ $homeLink }}" class="btn btn-primary">
         {{ i18n "goHome" }}
       </a>
-      <a :href="articlesLink" class="btn btn-secondary">
+      <a href="{{ if eq .Lang "it" }}/it{{ end }}/articles/" class="btn btn-secondary">
         {{ i18n "browseArticles" }}
       </a>
-      <a :href="contactLink" class="btn btn-outline">
+      <a href="{{ if eq .Lang "it" }}/it{{ end }}/is/here/" class="btn btn-outline">
         {{ i18n "contactSupport" }}
       </a>
     </div>