Skip to content

Commit d4b5bd3

Browse files
committed
f
1 parent 9bb5984 commit d4b5bd3

File tree

3 files changed

+62
-10
lines changed

3 files changed

+62
-10
lines changed

.github/workflows/build_master.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,22 @@ jobs:
6060
# Clone the searchindex repo
6161
git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo
6262
63-
# Copy the searchindex file
63+
# Copy and compress the searchindex file
6464
cp "$ASSET" "/tmp/searchindex-repo/${FILENAME}"
65+
gzip -9 -k -f "$ASSET"
66+
cp "${ASSET}.gz" "/tmp/searchindex-repo/${FILENAME}.gz"
67+
68+
# Show compression stats
69+
ORIGINAL_SIZE=$(wc -c < "$ASSET")
70+
COMPRESSED_SIZE=$(wc -c < "${ASSET}.gz")
71+
RATIO=$(awk "BEGIN {printf \"%.1f\", ($COMPRESSED_SIZE / $ORIGINAL_SIZE) * 100}")
72+
echo "Compression: ${ORIGINAL_SIZE} bytes -> ${COMPRESSED_SIZE} bytes (${RATIO}%)"
6573
6674
# Commit and push
6775
cd /tmp/searchindex-repo
6876
git config user.name "GitHub Actions"
6977
git config user.email "[email protected]"
70-
git add "${FILENAME}"
78+
git add "${FILENAME}" "${FILENAME}.gz"
7179
git commit -m "Update ${FILENAME} from hacktricks-cloud build" || echo "No changes to commit"
7280
git push || echo "No changes to push"
7381

.github/workflows/translate_all.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,22 @@ jobs:
169169
# Clone the searchindex repo
170170
git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo
171171
172-
# Copy the searchindex file
172+
# Copy and compress the searchindex file
173173
cp "$ASSET" "/tmp/searchindex-repo/${FILENAME}"
174+
gzip -9 -k -f "$ASSET"
175+
cp "${ASSET}.gz" "/tmp/searchindex-repo/${FILENAME}.gz"
176+
177+
# Show compression stats
178+
ORIGINAL_SIZE=$(wc -c < "$ASSET")
179+
COMPRESSED_SIZE=$(wc -c < "${ASSET}.gz")
180+
RATIO=$(awk "BEGIN {printf \"%.1f\", ($COMPRESSED_SIZE / $ORIGINAL_SIZE) * 100}")
181+
echo "Compression: ${ORIGINAL_SIZE} bytes -> ${COMPRESSED_SIZE} bytes (${RATIO}%)"
174182
175183
# Commit and push
176184
cd /tmp/searchindex-repo
177185
git config user.name "GitHub Actions"
178186
git config user.email "[email protected]"
179-
git add "${FILENAME}"
187+
git add "${FILENAME}" "${FILENAME}.gz"
180188
git commit -m "Update ${FILENAME} from hacktricks-cloud build" || echo "No changes to commit"
181189
git push || echo "No changes to push"
182190

theme/ht_searcher.js

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,52 @@
2121
try { importScripts('https://cdn.jsdelivr.net/npm/[email protected]/elasticlunr.min.js'); }
2222
catch { importScripts(abs('/elasticlunr.min.js')); }
2323
24-
/* 2 — load a single index (remote → local) */
24+
/* 2 — decompress gzip data */
25+
async function decompressGzip(arrayBuffer){
26+
if(typeof DecompressionStream !== 'undefined'){
27+
/* Modern browsers: use native DecompressionStream */
28+
const stream = new Response(arrayBuffer).body.pipeThrough(new DecompressionStream('gzip'));
29+
const decompressed = await new Response(stream).arrayBuffer();
30+
return new TextDecoder().decode(decompressed);
31+
} else {
32+
/* Fallback: use pako library */
33+
if(typeof pako === 'undefined'){
34+
try { importScripts('https://cdn.jsdelivr.net/npm/[email protected]/dist/pako.min.js'); }
35+
catch(e){ throw new Error('pako library required for decompression: '+e); }
36+
}
37+
const uint8Array = new Uint8Array(arrayBuffer);
38+
const decompressed = pako.ungzip(uint8Array, {to: 'string'});
39+
return decompressed;
40+
}
41+
}
42+
43+
/* 3 — load a single index (remote → local) */
2544
async function loadIndex(remote, local, isCloud=false){
2645
let rawLoaded = false;
2746
if(remote){
47+
/* Try compressed version first */
2848
try {
29-
const r = await fetch(remote,{mode:'cors'});
30-
if (!r.ok) throw new Error('HTTP '+r.status);
31-
importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'})));
32-
rawLoaded = true;
33-
} catch(e){ console.warn('remote',remote,'failed →',e); }
49+
const gzUrl = remote + '.gz';
50+
const r = await fetch(gzUrl,{mode:'cors'});
51+
if (r.ok) {
52+
const compressed = await r.arrayBuffer();
53+
const text = await decompressGzip(compressed);
54+
importScripts(URL.createObjectURL(new Blob([text],{type:'application/javascript'})));
55+
rawLoaded = true;
56+
console.log('Loaded compressed',gzUrl);
57+
}
58+
} catch(e){ console.warn('compressed',remote+'.gz','failed →',e); }
59+
60+
/* Fall back to uncompressed if compressed failed */
61+
if(!rawLoaded){
62+
try {
63+
const r = await fetch(remote,{mode:'cors'});
64+
if (!r.ok) throw new Error('HTTP '+r.status);
65+
importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'})));
66+
rawLoaded = true;
67+
console.log('Loaded uncompressed',remote);
68+
} catch(e){ console.warn('remote',remote,'failed →',e); }
69+
}
3470
}
3571
if(!rawLoaded && local){
3672
try { importScripts(abs(local)); rawLoaded = true; }

0 commit comments

Comments
 (0)