]> danix's work - danix.xyz-2.git/commitdiff
fix: detect language from permalink instead of .Lang in 404 template
authorDanilo M. <redacted>
Fri, 17 Apr 2026 09:44:47 +0000 (11:44 +0200)
committerDanilo M. <redacted>
Fri, 17 Apr 2026 09:44:47 +0000 (11:44 +0200)
Hugo's .Lang is unreliable in 404 context. Changed to detect language from
the request permalink (checking for /it/ prefix) to properly route Italian
404 pages to Italian content sections.

Co-Authored-By: Claude Haiku 4.5 <redacted>
themes/danix-xyz-hacker/layouts/404.html

index a81f34d228ba324bb90690cc6d8f11ef0784bac9..efae232a9187bfdbfb7d3ec6014a94f75106a9fa 100644 (file)
@@ -77,17 +77,21 @@ window.articlesData = [
 
     <!-- Navigation Links -->
     <div class="space-y-4 flex flex-col items-center mb-12">
-      {{ $homeLink := "/" }}
-      {{ if eq .Lang "it" }}
-        {{ $homeLink = "/it/" }}
+      {{ $lang := "en" }}
+      {{ if in .Permalink "/it/" }}
+        {{ $lang = "it" }}
       {{ end }}
-      <a href="{{ $homeLink }}" class="btn btn-primary">
+      {{ $prefix := "" }}
+      {{ if eq $lang "it" }}
+        {{ $prefix = "/it" }}
+      {{ end }}
+      <a href="{{ $prefix }}/" class="btn btn-primary">
         {{ i18n "goHome" }}
       </a>
-      <a href="{{ if eq .Lang "it" }}/it{{ end }}/articles/" class="btn btn-secondary">
+      <a href="{{ $prefix }}/articles/" class="btn btn-secondary">
         {{ i18n "browseArticles" }}
       </a>
-      <a href="{{ if eq .Lang "it" }}/it{{ end }}/is/here/" class="btn btn-outline">
+      <a href="{{ $prefix }}/is/here/" class="btn btn-outline">
         {{ i18n "contactSupport" }}
       </a>
     </div>