From 58f5fb17af226e8eb5338aa514a346826077232d Mon Sep 17 00:00:00 2001 From: carlospolop Date: Sat, 4 Oct 2025 01:46:26 +0200 Subject: [PATCH] f --- .github/workflows/build_master.yml | 3 +-- .github/workflows/translate_all.yml | 16 +++++++-------- theme/ht_searcher.js | 32 ++++++++++++----------------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build_master.yml b/.github/workflows/build_master.yml index a675592a2..a8e3cfb84 100644 --- a/.github/workflows/build_master.yml +++ b/.github/workflows/build_master.yml @@ -88,9 +88,8 @@ jobs: RATIO=$(awk "BEGIN {printf \"%.1f\", ($COMPRESSED_SIZE / $ORIGINAL_SIZE) * 100}") echo "Compression: ${ORIGINAL_SIZE} bytes -> ${COMPRESSED_SIZE} bytes (${RATIO}%)" - # Copy both versions to the searchindex repo + # Copy ONLY the .gz version to the searchindex repo (no uncompressed .js) cd /tmp/searchindex-repo - cp "${GITHUB_WORKSPACE}/${ASSET}" "${FILENAME}" cp "${GITHUB_WORKSPACE}/${ASSET}.gz" "${FILENAME}.gz" # Stage all files diff --git a/.github/workflows/translate_all.yml b/.github/workflows/translate_all.yml index 341618fd6..a8b687312 100644 --- a/.github/workflows/translate_all.yml +++ b/.github/workflows/translate_all.yml @@ -175,10 +175,8 @@ jobs: # Clone the searchindex repo git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo - # Copy and compress the searchindex file - cp "$ASSET" "/tmp/searchindex-repo/${FILENAME}" + # Compress the searchindex file gzip -9 -k -f "$ASSET" - cp "${ASSET}.gz" "/tmp/searchindex-repo/${FILENAME}.gz" # Show compression stats ORIGINAL_SIZE=$(wc -c < "$ASSET") @@ -186,11 +184,14 @@ jobs: RATIO=$(awk "BEGIN {printf \"%.1f\", ($COMPRESSED_SIZE / $ORIGINAL_SIZE) * 100}") echo "Compression: ${ORIGINAL_SIZE} bytes -> ${COMPRESSED_SIZE} bytes (${RATIO}%)" + # Copy ONLY the .gz version to the searchindex repo (no uncompressed .js) + cp "${ASSET}.gz" "/tmp/searchindex-repo/${FILENAME}.gz" + # Commit and push with retry logic cd /tmp/searchindex-repo git config user.name "GitHub Actions" git config user.email "github-actions@github.com" - git add "${FILENAME}" "${FILENAME}.gz" + git add "${FILENAME}.gz" if git diff --staged --quiet; then echo "No changes to commit" @@ -223,12 +224,11 @@ jobs: git config user.name "GitHub Actions" git config user.email "github-actions@github.com" - # Re-copy and compress the searchindex file - cp "$ASSET" "${FILENAME}" + # Re-copy ONLY the .gz version (no uncompressed .js) cp "${ASSET}.gz" "${FILENAME}.gz" - git add "${FILENAME}" "${FILENAME}.gz" - git commit -m "Update ${FILENAME} from hacktricks-cloud build" + git add "${FILENAME}.gz" + git commit -m "Update ${FILENAME}.gz from hacktricks-cloud build" echo "Re-cloned and re-committed, will retry push..." else echo "Rebase failed for unknown reason, retrying anyway..." diff --git a/theme/ht_searcher.js b/theme/ht_searcher.js index e4f347315..f94dc1261 100644 --- a/theme/ht_searcher.js +++ b/theme/ht_searcher.js @@ -44,32 +44,25 @@ async function loadIndex(remote, local, isCloud=false){ let rawLoaded = false; if(remote){ - /* Try compressed version first */ + /* Try ONLY compressed version from GitHub (remote already includes .js.gz) */ try { - const gzUrl = remote + '.gz'; - const r = await fetch(gzUrl,{mode:'cors'}); + const r = await fetch(remote,{mode:'cors'}); if (r.ok) { const compressed = await r.arrayBuffer(); const text = await decompressGzip(compressed); importScripts(URL.createObjectURL(new Blob([text],{type:'application/javascript'}))); rawLoaded = true; - console.log('Loaded compressed',gzUrl); + console.log('Loaded compressed from GitHub:',remote); } - } catch(e){ console.warn('compressed',remote+'.gz','failed →',e); } - - /* Fall back to uncompressed if compressed failed */ - if(!rawLoaded){ - try { - const r = await fetch(remote,{mode:'cors'}); - if (!r.ok) throw new Error('HTTP '+r.status); - importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'}))); - rawLoaded = true; - console.log('Loaded uncompressed',remote); - } catch(e){ console.warn('remote',remote,'failed →',e); } - } + } catch(e){ console.warn('compressed GitHub',remote,'failed →',e); } } + /* If remote (GitHub) failed, fall back to local uncompressed file */ if(!rawLoaded && local){ - try { importScripts(abs(local)); rawLoaded = true; } + try { + importScripts(abs(local)); + rawLoaded = true; + console.log('Loaded local fallback:',local); + } catch(e){ console.error('local',local,'failed →',e); } } if(!rawLoaded) return null; /* give up on this index */ @@ -106,8 +99,9 @@ const lang = data.lang || 'en'; const searchindexBase = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-searchindex/main'; - const mainFilenames = Array.from(new Set(['searchindex-' + lang + '.js', 'searchindex-en.js'])); - const cloudFilenames = Array.from(new Set(['searchindex-cloud-' + lang + '.js', 'searchindex-cloud-en.js'])); + /* Remote sources are .js.gz (compressed), local fallback is .js (uncompressed) */ + const mainFilenames = Array.from(new Set(['searchindex-' + lang + '.js.gz', 'searchindex-en.js.gz'])); + const cloudFilenames = Array.from(new Set(['searchindex-cloud-' + lang + '.js.gz', 'searchindex-cloud-en.js.gz'])); const MAIN_REMOTE_SOURCES = mainFilenames.map(function(filename) { return searchindexBase + '/' + filename; }); const CLOUD_REMOTE_SOURCES = cloudFilenames.map(function(filename) { return searchindexBase + '/' + filename; });