From 35bb5d3b6945f5dc8abe058c3f9b7bb294cc600e Mon Sep 17 00:00:00 2001 From: Carlos Polop Date: Sun, 20 Apr 2025 02:54:48 +0200 Subject: [PATCH] fix links --- theme/ht_searcher.js | 104 +++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/theme/ht_searcher.js b/theme/ht_searcher.js index 2fffdb8b2..e77213e96 100644 --- a/theme/ht_searcher.js +++ b/theme/ht_searcher.js @@ -470,69 +470,67 @@ window.search = window.search || {}; // Display results showResults(true); } - async function loadSearchIndex(lang = 'en') { - /* ---------- configuration ---------- */ - const branch = lang === 'en' ? 'master' : lang; - const remoteJson = `https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/refs/heads/${branch}/searchindex.json`; - const remoteJs = `https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/refs/heads/${branch}/searchindex.js`; - const localJson = 'searchindex.json'; - const localJs = 'searchindex.js'; - const TIMEOUT_MS = 5_000; - /* ----------------------------------- */ - + + (async function loadSearchIndex(lang = window.lang || 'en') { + /* ───────── paths ───────── */ + const branch = lang === 'en' ? 'master' : lang; + const baseRemote = `https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/${branch}`; + const remoteJson = `${baseRemote}/searchindex.json`; + const remoteJs = `${baseRemote}/searchindex.js`; + const localJson = './searchindex.json'; + const localJs = './searchindex.js'; + const TIMEOUT_MS = 5_000; + + /* ───────── helpers ───────── */ const fetchWithTimeout = (url, opt = {}) => - Promise.race([ + Promise.race([ fetch(url, opt), new Promise((_, r) => setTimeout(() => r(new Error('timeout')), TIMEOUT_MS)) - ]); - - /* 1️⃣ remote JSON -------------------------------------------------- */ - try { - const r = await fetchWithTimeout(remoteJson); - if (!r.ok) throw new Error(r.status); - return init(await r.json()); - } catch (err) { - console.warn('Remote searchindex.json failed →', err); - } - - /* 2️⃣ local JSON --------------------------------------------------- */ - try { - const r = await fetch(localJson); - if (!r.ok) throw new Error(r.status); - return init(await r.json()); - } catch (err) { - console.warn('Local searchindex.json failed →', err); - } - - /* helper to load a