Skip to content

Commit 9bb5984

Browse files
committed
f
1 parent 3da7552 commit 9bb5984

File tree

3 files changed

+65
-70
lines changed

3 files changed

+65
-70
lines changed

.github/workflows/build_master.yml

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,59 +35,41 @@ jobs:
3535
- name: Build mdBook
3636
run: MDBOOK_BOOK__LANGUAGE=en mdbook build || (echo "Error logs" && cat hacktricks-preprocessor-error.log && echo "" && echo "" && echo "Debug logs" && (cat hacktricks-preprocessor.log | tail -n 20) && exit 1)
3737

38-
- name: Install GitHub CLI
39-
run: |
40-
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
41-
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
42-
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
43-
&& sudo apt update \
44-
&& sudo apt install gh -y
45-
46-
- name: Publish search index release asset
38+
- name: Push search index to hacktricks-searchindex repo
4739
shell: bash
4840
env:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
5042
run: |
5143
set -euo pipefail
5244
5345
ASSET="book/searchindex.js"
54-
TAG="searchindex-en"
55-
TITLE="Search Index (en)"
46+
TARGET_REPO="HackTricks-wiki/hacktricks-searchindex"
47+
FILENAME="searchindex-cloud-en.js"
5648
5749
if [ ! -f "$ASSET" ]; then
5850
echo "Expected $ASSET to exist after build" >&2
5951
exit 1
6052
fi
6153
62-
TOKEN="${GITHUB_TOKEN}"
54+
TOKEN="${PAT_TOKEN}"
6355
if [ -z "$TOKEN" ]; then
64-
echo "No token available for GitHub CLI" >&2
56+
echo "No PAT_TOKEN available" >&2
6557
exit 1
6658
fi
67-
export GH_TOKEN="$TOKEN"
6859
69-
# Delete the release if it exists
70-
echo "Checking if release $TAG exists..."
71-
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
72-
echo "Release $TAG already exists, deleting it..."
73-
gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" --cleanup-tag || {
74-
echo "Failed to delete release, trying without cleanup-tag..."
75-
gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" || {
76-
echo "Warning: Could not delete existing release, will try to recreate..."
77-
}
78-
}
79-
sleep 2 # Give GitHub API a moment to process the deletion
80-
else
81-
echo "Release $TAG does not exist, proceeding with creation..."
82-
fi
60+
# Clone the searchindex repo
61+
git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo
62+
63+
# Copy the searchindex file
64+
cp "$ASSET" "/tmp/searchindex-repo/${FILENAME}"
8365
84-
# Create new release (with force flag to overwrite if deletion failed)
85-
gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for master" --repo "$GITHUB_REPOSITORY" || {
86-
echo "Failed to create release, trying with force flag..."
87-
gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" --cleanup-tag >/dev/null 2>&1 || true
88-
sleep 2
89-
gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for master" --repo "$GITHUB_REPOSITORY"
90-
}
66+
# Commit and push
67+
cd /tmp/searchindex-repo
68+
git config user.name "GitHub Actions"
69+
git config user.email "[email protected]"
70+
git add "${FILENAME}"
71+
git commit -m "Update ${FILENAME} from hacktricks-cloud build" || echo "No changes to commit"
72+
git push || echo "No changes to push"
9173
9274
# Login in AWs
9375
- name: Configure AWS credentials using OIDC

.github/workflows/translate_all.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,37 +144,41 @@ jobs:
144144
git pull
145145
MDBOOK_BOOK__LANGUAGE=$BRANCH mdbook build || (echo "Error logs" && cat hacktricks-preprocessor-error.log && echo "" && echo "" && echo "Debug logs" && (cat hacktricks-preprocessor.log | tail -n 20) && exit 1)
146146
147-
- name: Publish search index release asset
147+
- name: Push search index to hacktricks-searchindex repo
148148
shell: bash
149149
env:
150-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
150+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
151151
run: |
152152
set -euo pipefail
153153
154154
ASSET="book/searchindex.js"
155-
TAG="searchindex-${BRANCH}"
156-
TITLE="Search Index (${BRANCH})"
155+
TARGET_REPO="HackTricks-wiki/hacktricks-searchindex"
156+
FILENAME="searchindex-cloud-${BRANCH}.js"
157157
158158
if [ ! -f "$ASSET" ]; then
159159
echo "Expected $ASSET to exist after build" >&2
160160
exit 1
161161
fi
162162
163-
TOKEN="${GITHUB_TOKEN}"
163+
TOKEN="${PAT_TOKEN}"
164164
if [ -z "$TOKEN" ]; then
165-
echo "No token available for GitHub CLI" >&2
165+
echo "No PAT_TOKEN available" >&2
166166
exit 1
167167
fi
168-
export GH_TOKEN="$TOKEN"
169168
170-
# Delete the release if it exists
171-
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
172-
echo "Release $TAG already exists, deleting it..."
173-
gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY"
174-
fi
169+
# Clone the searchindex repo
170+
git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo
171+
172+
# Copy the searchindex file
173+
cp "$ASSET" "/tmp/searchindex-repo/${FILENAME}"
175174
176-
# Create new release
177-
gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for $BRANCH" --repo "$GITHUB_REPOSITORY"
175+
# Commit and push
176+
cd /tmp/searchindex-repo
177+
git config user.name "GitHub Actions"
178+
git config user.email "[email protected]"
179+
git add "${FILENAME}"
180+
git commit -m "Update ${FILENAME} from hacktricks-cloud build" || echo "No changes to commit"
181+
git push || echo "No changes to push"
178182
179183
# Login in AWs
180184
- name: Configure AWS credentials using OIDC

theme/ht_searcher.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,41 @@
6060
}
6161
6262
return local ? loadIndex(null, local, isCloud) : null;
63-
} (async () => {
64-
const htmlLang = (document.documentElement.lang || 'en').toLowerCase();
65-
const lang = htmlLang.split('-')[0];
66-
const mainReleaseBase = 'https://github.com/HackTricks-wiki/hacktricks/releases/download';
67-
const cloudReleaseBase = 'https://github.com/HackTricks-wiki/hacktricks-cloud/releases/download';
63+
}
64+
65+
let built = [];
66+
const MAX = 30, opts = {bool:'AND', expand:true};
67+
68+
self.onmessage = async ({data}) => {
69+
if(data.type === 'init'){
70+
const lang = data.lang || 'en';
71+
const searchindexBase = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-searchindex/main';
6872
69-
const mainTags = Array.from(new Set(['searchindex-' + lang, 'searchindex-en', 'searchindex-master']));
70-
const cloudTags = Array.from(new Set(['searchindex-' + lang, 'searchindex-en', 'searchindex-master']));
73+
const mainFilenames = Array.from(new Set(['searchindex-' + lang + '.js', 'searchindex-en.js']));
74+
const cloudFilenames = Array.from(new Set(['searchindex-cloud-' + lang + '.js', 'searchindex-cloud-en.js']));
7175
72-
const MAIN_REMOTE_SOURCES = mainTags.map(function(tag) { return mainReleaseBase + '/' + tag + '/searchindex.js'; });
73-
const CLOUD_REMOTE_SOURCES = cloudTags.map(function(tag) { return cloudReleaseBase + '/' + tag + '/searchindex.js'; });
76+
const MAIN_REMOTE_SOURCES = mainFilenames.map(function(filename) { return searchindexBase + '/' + filename; });
77+
const CLOUD_REMOTE_SOURCES = cloudFilenames.map(function(filename) { return searchindexBase + '/' + filename; });
7478
75-
const indices = [];
76-
const main = await loadWithFallback(MAIN_REMOTE_SOURCES , '/searchindex-book.js', false); if(main) indices.push(main);
77-
const cloud= await loadWithFallback(CLOUD_REMOTE_SOURCES, '/searchindex.js', true ); if(cloud) indices.push(cloud);
79+
const indices = [];
80+
const main = await loadWithFallback(MAIN_REMOTE_SOURCES , '/searchindex-book.js', false); if(main) indices.push(main);
81+
const cloud= await loadWithFallback(CLOUD_REMOTE_SOURCES, '/searchindex.js', true ); if(cloud) indices.push(cloud);
7882
if(!indices.length){ postMessage({ready:false, error:'no-index'}); return; }
7983
8084
/* build index objects */
81-
const built = indices.map(d => ({
85+
built = indices.map(d => ({
8286
idx : elasticlunr.Index.load(d.json),
8387
urls: d.urls,
8488
cloud: d.cloud,
8589
base: d.cloud ? 'https://cloud.hacktricks.wiki/' : ''
8690
}));
8791
8892
postMessage({ready:true});
89-
const MAX = 30, opts = {bool:'AND', expand:true};
90-
91-
self.onmessage = ({data:q}) => {
92-
if(!q){ postMessage([]); return; }
93+
return;
94+
}
95+
96+
const q = data.query || data;
97+
if(!q){ postMessage([]); return; }
9398
9499
const all = [];
95100
for(const s of built){
@@ -110,12 +115,16 @@
110115
}
111116
all.sort((a,b)=>b.norm-a.norm);
112117
postMessage(all.slice(0,MAX));
113-
};
114-
})();
118+
};
115119
`;
116120

117121
/* ───────────── 2. spawn worker ───────────── */
118122
const worker = new Worker(URL.createObjectURL(new Blob([workerCode],{type:'application/javascript'})));
123+
124+
/* ───────────── 2.1. initialize worker with language ───────────── */
125+
const htmlLang = (document.documentElement.lang || 'en').toLowerCase();
126+
const lang = htmlLang.split('-')[0];
127+
worker.postMessage({type: 'init', lang: lang});
119128

120129
/* ───────────── 3. DOM refs ─────────────── */
121130
const wrap = document.getElementById('search-wrapper');
@@ -182,7 +191,7 @@
182191
else if([DOWN,UP,ENTER].includes(e.keyCode) && document.activeElement!==bar){const cur=list.querySelector('li.focus'); if(!cur) return; e.preventDefault(); if(e.keyCode===DOWN){const nxt=cur.nextElementSibling; if(nxt){cur.classList.remove('focus'); nxt.classList.add('focus');}} else if(e.keyCode===UP){const prv=cur.previousElementSibling; cur.classList.remove('focus'); if(prv){prv.classList.add('focus');} else {bar.focus();}} else {const a=cur.querySelector('a'); if(a) window.location.assign(a.href);}}
183192
});
184193

185-
bar.addEventListener('input',e=>{ clearTimeout(debounce); debounce=setTimeout(()=>worker.postMessage(e.target.value.trim()),120); });
194+
bar.addEventListener('input',e=>{ clearTimeout(debounce); debounce=setTimeout(()=>worker.postMessage({query: e.target.value.trim()}),120); });
186195

187196
/* ───────────── worker messages ───────────── */
188197
worker.onmessage = ({data}) => {

0 commit comments

Comments
 (0)