Skip to content

Commit e839fdd

Browse files
committed
f
1 parent b7832d4 commit e839fdd

2 files changed

Lines changed: 87 additions & 15 deletions

File tree

AGENTS.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# AGENTS.md
2+
3+
Guidance for future agents working in this repository.
4+
5+
## Repository Context
6+
7+
This is the HackTricks Cloud mdBook repository. The related main book lives at:
8+
9+
`/Users/carlospolop/git/hacktricks`
10+
11+
Changes to shared theme/search behavior often need to be applied in both repositories.
12+
13+
## Search Index Loading Contract
14+
15+
The custom search UI lives in:
16+
17+
`theme/ht_searcher.js`
18+
19+
There may also be a generated copy at:
20+
21+
`book/theme/ht_searcher.js`
22+
23+
If production is deploying the already-built `book/` directory, update both copies or rebuild the
24+
book before deployment.
25+
26+
The search index loading order is important and cost-sensitive:
27+
28+
1. Load every language-specific and fallback search index from the GitHub repository:
29+
`HackTricks-wiki/hacktricks-searchindex`
30+
2. Only if all GitHub-hosted candidates fail, fall back to the same-origin mdBook output.
31+
32+
Do not place the local `/searchindex.js` fallback before any GitHub-hosted fallback such as
33+
`searchindex-cloud-en.js.gz`. Serving `searchindex.js` from `cloud.hacktricks.wiki` in production is expensive.
34+
35+
For this repo, the expected local fallback is:
36+
37+
`/searchindex.js`
38+
39+
The main-book fallback for this repo is:
40+
41+
`/searchindex-book.js`
42+
43+
That file is only a fallback. The primary source must remain the remote
44+
`searchindex-<lang>.js.gz` and `searchindex-cloud-<lang>.js.gz` files in
45+
`HackTricks-wiki/hacktricks-searchindex`.
46+
47+
## Search Index Publishing
48+
49+
The workflows that publish encrypted compressed search indexes to
50+
`HackTricks-wiki/hacktricks-searchindex` are:
51+
52+
- `.github/workflows/build_master.yml`
53+
- `.github/workflows/translate_all.yml`
54+
55+
The generated source file is `book/searchindex.js`. The published remote artifact names are:
56+
57+
- `searchindex-cloud-en.js.gz`
58+
- `searchindex-cloud-<lang>.js.gz`
59+
60+
The browser loader expects the remote `.js.gz` files to be XOR-encrypted gzip payloads using the
61+
key defined in `theme/ht_searcher.js`.
62+
63+
## Build And Validation
64+
65+
Common local checks:
66+
67+
- `node --check theme/ht_searcher.js`
68+
- `mdbook build`
69+
70+
If `mdbook build` fails, check:
71+
72+
- `hacktricks-preprocessor-error.log`
73+
- `hacktricks-preprocessor.log`
74+
75+
## Editing Notes
76+
77+
- Prefer `rg` for searching.
78+
- Keep generated `book/` output out of commits unless explicitly requested. Search loader fixes are
79+
an exception when the already-built pages must be corrected immediately.
80+
- If changing shared theme behavior, compare and update the matching file in
81+
`/Users/carlospolop/git/hacktricks`.
82+
- Do not revert unrelated local changes.

theme/ht_searcher.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,10 @@
8686
}
8787
8888
async function loadWithFallback(remotes, local, isCloud=false){
89-
if(remotes.length){
90-
const [primary, ...secondary] = remotes;
91-
const primaryData = await loadIndex(primary, null, isCloud);
92-
if(primaryData) return primaryData;
93-
94-
if(local){
95-
const localData = await loadIndex(null, local, isCloud);
96-
if(localData) return localData;
97-
}
98-
99-
for (const remote of secondary){
100-
const data = await loadIndex(remote, null, isCloud);
101-
if(data) return data;
102-
}
89+
/* Exhaust every GitHub-hosted index before touching the production origin. */
90+
for (const remote of remotes){
91+
const data = await loadIndex(remote, null, isCloud);
92+
if(data) return data;
10393
}
10494
10595
return local ? loadIndex(null, local, isCloud) : null;
@@ -271,4 +261,4 @@
271261
listOut.classList.toggle('hidden',!docs.length);
272262
};
273263
})();
274-
264+

0 commit comments

Comments
 (0)