]> danix's work - danix.xyz-2.git/commitdiff
fix: make search index language-aware
authorDanilo M. <redacted>
Mon, 20 Apr 2026 12:12:20 +0000 (14:12 +0200)
committerDanilo M. <redacted>
Mon, 20 Apr 2026 12:12:20 +0000 (14:12 +0200)
loadSearchIndex() now detects current language from URL pathname. If on /it/* path, loads /it/search-index.json; otherwise loads /search-index.json. Ensures search results link to correct language version of articles.

Co-Authored-By: Claude Haiku 4.5 <redacted>
themes/danix-xyz-hacker/assets/js/search.js

index 94c63236d6dd4deec7020c2419b6fde5203b3f87..8fb62622dcae6e51fd1aaf709b3e3a859a3754c9 100644 (file)
@@ -1,10 +1,14 @@
-// Lazy-load search index from JSON file
+// Lazy-load search index from JSON file (language-aware)
 async function loadSearchIndex() {
   if (window.searchIndex) {
     return window.searchIndex;
   }
   try {
-    const response = await fetch('/search-index.json');
+    // Detect current language from URL
+    const isItalian = window.location.pathname.startsWith('/it/');
+    const indexPath = isItalian ? '/it/search-index.json' : '/search-index.json';
+
+    const response = await fetch(indexPath);
     if (!response.ok) throw new Error('Failed to load search index');
     window.searchIndex = await response.json();
     return window.searchIndex;