mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-05 20:40:18 -08:00
fix searchindex
This commit is contained in:
88
.github/workflows/build_master.yml
vendored
88
.github/workflows/build_master.yml
vendored
@@ -35,63 +35,59 @@ jobs:
|
|||||||
- name: Build mdBook
|
- name: Build mdBook
|
||||||
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)
|
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)
|
||||||
|
|
||||||
- name: Update searchindex in repo (purge history, keep current on HEAD)
|
- name: Install GitHub CLI
|
||||||
|
run: |
|
||||||
|
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||||
|
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||||
|
&& 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 \
|
||||||
|
&& sudo apt update \
|
||||||
|
&& sudo apt install gh -y
|
||||||
|
|
||||||
|
- name: Publish search index release asset
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
pwd
|
ASSET="book/searchindex.js"
|
||||||
ls -la
|
TAG="searchindex-en"
|
||||||
ls -la book
|
TITLE="Search Index (en)"
|
||||||
|
|
||||||
git config --global --add safe.directory /__w/hacktricks-cloud/hacktricks-cloud
|
if [ ! -f "$ASSET" ]; then
|
||||||
git config --global user.email "build@example.com"
|
echo "Expected $ASSET to exist after build" >&2
|
||||||
git config --global user.name "Build master"
|
exit 1
|
||||||
git config pull.rebase false
|
|
||||||
|
|
||||||
# Ensure we're on the target branch and up to date
|
|
||||||
# Handle force-pushed branches by resetting to origin/master
|
|
||||||
git fetch origin
|
|
||||||
git reset --hard origin/master
|
|
||||||
|
|
||||||
# Choose the file to keep at HEAD:
|
|
||||||
# 1) Prefer freshly built version from book/
|
|
||||||
# 2) Fallback to the file currently at HEAD (if it exists)
|
|
||||||
HAS_FILE=0
|
|
||||||
if [ -f "book/searchindex.js" ]; then
|
|
||||||
cp "book/searchindex.js" /tmp/sidx.js
|
|
||||||
HAS_FILE=1
|
|
||||||
elif git cat-file -e "HEAD:searchindex.js" 2>/dev/null; then
|
|
||||||
git show "HEAD:searchindex.js" > /tmp/sidx.js
|
|
||||||
HAS_FILE=1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Skip if there's nothing to purge AND nothing to keep
|
TOKEN="${PAT_TOKEN:-${GITHUB_TOKEN:-}}"
|
||||||
if [ "$HAS_FILE" = "1" ] || git rev-list -n 1 HEAD -- "searchindex.js" >/dev/null 2>&1; then
|
if [ -z "$TOKEN" ]; then
|
||||||
# Fail early if working tree is dirty (avoid confusing rewrites)
|
echo "No token available for GitHub CLI" >&2
|
||||||
git diff --quiet || { echo "Working tree has uncommitted changes; aborting purge." >&2; exit 1; }
|
exit 1
|
||||||
|
fi
|
||||||
|
export GH_TOKEN="$TOKEN"
|
||||||
|
|
||||||
# Install git-filter-repo and ensure it's on PATH
|
# Delete the release if it exists
|
||||||
python -m pip install --quiet --user git-filter-repo
|
echo "Checking if release $TAG exists..."
|
||||||
export PATH="$HOME/.local/bin:$PATH"
|
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
|
||||||
|
echo "Release $TAG already exists, deleting it..."
|
||||||
# Rewrite ONLY the current branch, dropping all historical blobs of searchindex.js
|
gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" --cleanup-tag || {
|
||||||
git filter-repo --force --path "searchindex.js" --invert-paths --refs "$(git symbolic-ref -q HEAD)"
|
echo "Failed to delete release, trying without cleanup-tag..."
|
||||||
|
gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" || {
|
||||||
# Re-add the current version on top of rewritten history (keep it in HEAD)
|
echo "Warning: Could not delete existing release, will try to recreate..."
|
||||||
if [ "$HAS_FILE" = "1" ]; then
|
}
|
||||||
mv /tmp/sidx.js "searchindex.js"
|
}
|
||||||
git add "searchindex.js"
|
sleep 2 # Give GitHub API a moment to process the deletion
|
||||||
git commit -m "Update searchindex (purged history; keep current)"
|
|
||||||
else
|
else
|
||||||
echo "No current searchindex.js to re-add after purge."
|
echo "Release $TAG does not exist, proceeding with creation..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Safer force push (only updates if remote hasn't advanced)
|
# Create new release (with force flag to overwrite if deletion failed)
|
||||||
git push --force-with-lease
|
gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for master" --repo "$GITHUB_REPOSITORY" || {
|
||||||
else
|
echo "Failed to create release, trying with force flag..."
|
||||||
echo "Nothing to purge; skipping."
|
gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY" --cleanup-tag >/dev/null 2>&1 || true
|
||||||
fi
|
sleep 2
|
||||||
|
gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for master" --repo "$GITHUB_REPOSITORY"
|
||||||
|
}
|
||||||
|
|
||||||
# Login in AWs
|
# Login in AWs
|
||||||
- name: Configure AWS credentials using OIDC
|
- name: Configure AWS credentials using OIDC
|
||||||
|
|||||||
69
.github/workflows/translate_all.yml
vendored
69
.github/workflows/translate_all.yml
vendored
@@ -66,7 +66,13 @@ jobs:
|
|||||||
- name: Update and download scripts
|
- name: Update and download scripts
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install wget -y
|
# Install GitHub CLI properly
|
||||||
|
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||||
|
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||||
|
&& 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 \
|
||||||
|
&& sudo apt update \
|
||||||
|
&& sudo apt install gh -y \
|
||||||
|
&& sudo apt-get install -y wget
|
||||||
wget -O /tmp/get_and_save_refs.py https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/master/scripts/get_and_save_refs.py
|
wget -O /tmp/get_and_save_refs.py https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/master/scripts/get_and_save_refs.py
|
||||||
wget -O /tmp/compare_and_fix_refs.py https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/master/scripts/compare_and_fix_refs.py
|
wget -O /tmp/compare_and_fix_refs.py https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/master/scripts/compare_and_fix_refs.py
|
||||||
wget -O /tmp/translator.py https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/master/scripts/translator.py
|
wget -O /tmp/translator.py https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/master/scripts/translator.py
|
||||||
@@ -138,56 +144,37 @@ jobs:
|
|||||||
git pull
|
git pull
|
||||||
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)
|
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)
|
||||||
|
|
||||||
- name: Update searchindex.js in repo (purge history, keep current on HEAD)
|
- name: Publish search index release asset
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Be explicit about workspace trust (avoids "dubious ownership")
|
ASSET="book/searchindex.js"
|
||||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
TAG="searchindex-${BRANCH}"
|
||||||
|
TITLE="Search Index (${BRANCH})"
|
||||||
|
|
||||||
git checkout "$BRANCH"
|
if [ ! -f "$ASSET" ]; then
|
||||||
git fetch origin "$BRANCH" --quiet
|
echo "Expected $ASSET to exist after build" >&2
|
||||||
git pull --ff-only
|
exit 1
|
||||||
|
|
||||||
# Choose the file to keep at HEAD:
|
|
||||||
# 1) Prefer freshly built version from book/
|
|
||||||
# 2) Fallback to the file currently at HEAD (if it exists)
|
|
||||||
HAS_FILE=0
|
|
||||||
if [ -f "book/searchindex.js" ]; then
|
|
||||||
cp "book/searchindex.js" /tmp/sidx.js
|
|
||||||
HAS_FILE=1
|
|
||||||
elif git cat-file -e "HEAD:searchindex.js" 2>/dev/null; then
|
|
||||||
git show "HEAD:searchindex.js" > /tmp/sidx.js
|
|
||||||
HAS_FILE=1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Skip if there's nothing to purge AND nothing to keep
|
TOKEN="${PAT_TOKEN:-${GITHUB_TOKEN:-}}"
|
||||||
if [ "$HAS_FILE" = "1" ] || git rev-list -n 1 "$BRANCH" -- "searchindex.js" >/dev/null 2>&1; then
|
if [ -z "$TOKEN" ]; then
|
||||||
# **Fail early if working tree is dirty** (prevents confusing filter results)
|
echo "No token available for GitHub CLI" >&2
|
||||||
git diff --quiet || { echo "Working tree has uncommitted changes; aborting purge." >&2; exit 1; }
|
exit 1
|
||||||
|
fi
|
||||||
|
export GH_TOKEN="$TOKEN"
|
||||||
|
|
||||||
# Make sure git-filter-repo is callable via `git filter-repo`
|
# Delete the release if it exists
|
||||||
python -m pip install --quiet --user git-filter-repo
|
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
|
||||||
export PATH="$HOME/.local/bin:$PATH"
|
echo "Release $TAG already exists, deleting it..."
|
||||||
|
gh release delete "$TAG" --yes --repo "$GITHUB_REPOSITORY"
|
||||||
# Rewrite ONLY this branch, dropping all historical blobs of searchindex.js
|
|
||||||
git filter-repo --force --path "searchindex.js" --invert-paths --refs "refs/heads/$BRANCH"
|
|
||||||
|
|
||||||
# Re-add the current version on top of rewritten history (keep it in HEAD)
|
|
||||||
if [ "$HAS_FILE" = "1" ]; then
|
|
||||||
mv /tmp/sidx.js "searchindex.js"
|
|
||||||
git add "searchindex.js"
|
|
||||||
git commit -m "Update searchindex (purged history; keep current)"
|
|
||||||
else
|
|
||||||
echo "No current searchindex.js to re-add after purge."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# **Safer force push** (prevents clobbering unexpected remote updates)
|
# Create new release
|
||||||
git push --force-with-lease origin "$BRANCH"
|
gh release create "$TAG" "$ASSET" --title "$TITLE" --notes "Automated search index build for $BRANCH" --repo "$GITHUB_REPOSITORY"
|
||||||
else
|
|
||||||
echo "Nothing to purge; skipping."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Login in AWs
|
# Login in AWs
|
||||||
- name: Configure AWS credentials using OIDC
|
- name: Configure AWS credentials using OIDC
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -35,3 +35,4 @@ book
|
|||||||
book/*
|
book/*
|
||||||
hacktricks-preprocessor.log
|
hacktricks-preprocessor.log
|
||||||
hacktricks-preprocessor-error.log
|
hacktricks-preprocessor-error.log
|
||||||
|
searchindex.js
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -24,13 +24,15 @@
|
|||||||
/* 2 — load a single index (remote → local) */
|
/* 2 — load a single index (remote → local) */
|
||||||
async function loadIndex(remote, local, isCloud=false){
|
async function loadIndex(remote, local, isCloud=false){
|
||||||
let rawLoaded = false;
|
let rawLoaded = false;
|
||||||
|
if(remote){
|
||||||
try {
|
try {
|
||||||
const r = await fetch(remote,{mode:'cors'});
|
const r = await fetch(remote,{mode:'cors'});
|
||||||
if (!r.ok) throw new Error('HTTP '+r.status);
|
if (!r.ok) throw new Error('HTTP '+r.status);
|
||||||
importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'})));
|
importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'})));
|
||||||
rawLoaded = true;
|
rawLoaded = true;
|
||||||
} catch(e){ console.warn('remote',remote,'failed →',e); }
|
} catch(e){ console.warn('remote',remote,'failed →',e); }
|
||||||
if(!rawLoaded){
|
}
|
||||||
|
if(!rawLoaded && local){
|
||||||
try { importScripts(abs(local)); rawLoaded = true; }
|
try { importScripts(abs(local)); rawLoaded = true; }
|
||||||
catch(e){ console.error('local',local,'failed →',e); }
|
catch(e){ console.error('local',local,'failed →',e); }
|
||||||
}
|
}
|
||||||
@@ -40,14 +42,39 @@
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
async function loadWithFallback(remotes, local, isCloud=false){
|
||||||
const MAIN_RAW = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/refs/heads/master/searchindex.js';
|
if(remotes.length){
|
||||||
const CLOUD_RAW = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/refs/heads/master/searchindex.js';
|
const [primary, ...secondary] = remotes;
|
||||||
|
const primaryData = await loadIndex(primary, null, isCloud);
|
||||||
|
if(primaryData) return primaryData;
|
||||||
|
|
||||||
|
if(local){
|
||||||
|
const localData = await loadIndex(null, local, isCloud);
|
||||||
|
if(localData) return localData;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const remote of secondary){
|
||||||
|
const data = await loadIndex(remote, null, isCloud);
|
||||||
|
if(data) return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return local ? loadIndex(null, local, isCloud) : null;
|
||||||
|
} (async () => {
|
||||||
|
const htmlLang = (document.documentElement.lang || 'en').toLowerCase();
|
||||||
|
const lang = htmlLang.split('-')[0];
|
||||||
|
const mainReleaseBase = 'https://github.com/HackTricks-wiki/hacktricks/releases/download';
|
||||||
|
const cloudReleaseBase = 'https://github.com/HackTricks-wiki/hacktricks-cloud/releases/download';
|
||||||
|
|
||||||
|
const mainTags = Array.from(new Set(['searchindex-' + lang, 'searchindex-en', 'searchindex-master']));
|
||||||
|
const cloudTags = Array.from(new Set(['searchindex-' + lang, 'searchindex-en', 'searchindex-master']));
|
||||||
|
|
||||||
|
const MAIN_REMOTE_SOURCES = mainTags.map(function(tag) { return mainReleaseBase + '/' + tag + '/searchindex.js'; });
|
||||||
|
const CLOUD_REMOTE_SOURCES = cloudTags.map(function(tag) { return cloudReleaseBase + '/' + tag + '/searchindex.js'; });
|
||||||
|
|
||||||
const indices = [];
|
const indices = [];
|
||||||
const main = await loadIndex(MAIN_RAW , '/searchindex-book.js', false); if(main) indices.push(main);
|
const main = await loadWithFallback(MAIN_REMOTE_SOURCES , '/searchindex-book.js', false); if(main) indices.push(main);
|
||||||
const cloud= await loadIndex(CLOUD_RAW, '/searchindex.js', true ); if(cloud) indices.push(cloud);
|
const cloud= await loadWithFallback(CLOUD_REMOTE_SOURCES, '/searchindex.js', true ); if(cloud) indices.push(cloud);
|
||||||
|
|
||||||
if(!indices.length){ postMessage({ready:false, error:'no-index'}); return; }
|
if(!indices.length){ postMessage({ready:false, error:'no-index'}); return; }
|
||||||
|
|
||||||
/* build index objects */
|
/* build index objects */
|
||||||
@@ -160,8 +187,16 @@
|
|||||||
/* ───────────── worker messages ───────────── */
|
/* ───────────── worker messages ───────────── */
|
||||||
worker.onmessage = ({data}) => {
|
worker.onmessage = ({data}) => {
|
||||||
if(data && data.ready!==undefined){
|
if(data && data.ready!==undefined){
|
||||||
if(data.ready){ icon.innerHTML=READY_ICON; icon.setAttribute('aria-label','Open search (S)'); }
|
if(data.ready){
|
||||||
else { icon.textContent='❌'; icon.setAttribute('aria-label','Search unavailable'); }
|
icon.innerHTML=READY_ICON;
|
||||||
|
icon.setAttribute('aria-label','Open search (S)');
|
||||||
|
icon.removeAttribute('title');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
icon.textContent='❌';
|
||||||
|
icon.setAttribute('aria-label','Search unavailable');
|
||||||
|
icon.setAttribute('title','Search is unavailable');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const docs=data, q=bar.value.trim(), terms=q.split(/\s+/).filter(Boolean);
|
const docs=data, q=bar.value.trim(), terms=q.split(/\s+/).filter(Boolean);
|
||||||
|
|||||||
Reference in New Issue
Block a user