Skip to content

Commit 8efafd6

Browse files
authored
fix(search-index): use en-US popularities for German (#12212)
Reorders the German search-index using the order from the English search-index, which is based on page popularity in terms of page views in the previous month.
1 parent a31ba5f commit 8efafd6

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

Diff for: .github/workflows/dev-build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ jobs:
169169
yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json
170170
yarn tool whatsdeployed $CONTENT_TRANSLATED_ROOT --output client/build/_whatsdeployed/translated-content.json
171171
172+
# Sort DE search index by en-US popularity.
173+
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
174+
172175
- name: Deploy with deployer
173176
env:
174177
# Set the CONTENT_ROOT first

Diff for: .github/workflows/prod-build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ jobs:
312312
yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json
313313
yarn tool whatsdeployed $CONTENT_TRANSLATED_ROOT --output client/build/_whatsdeployed/translated-content.json
314314
315+
# Sort DE search index by en-US popularity.
316+
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
317+
315318
- name: Update search index
316319
if: ${{ ! vars.SKIP_BUILD }}
317320
env:

Diff for: .github/workflows/stage-build.yml

+6
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ jobs:
314314
315315
yarn rari build --issues client/build/issues.json --templ-stats
316316
317+
# Sort DE search index by en-US popularity.
318+
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
319+
317320
# SSR all pages
318321
yarn render:html
319322
@@ -322,6 +325,9 @@ jobs:
322325
yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json
323326
yarn tool whatsdeployed $CONTENT_TRANSLATED_ROOT --output client/build/_whatsdeployed/translated-content.json
324327
328+
# Sort DE search index by en-US popularity.
329+
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
330+
325331
- name: Update search index
326332
if: ${{ ! vars.SKIP_BUILD }}
327333
env:

Diff for: .github/workflows/test-build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ jobs:
213213
yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json
214214
yarn tool whatsdeployed $CONTENT_TRANSLATED_ROOT --output client/build/_whatsdeployed/translated-content.json
215215
216+
# Sort DE search index by en-US popularity.
217+
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
218+
216219
- name: Authenticate with GCP
217220
uses: google-github-actions/auth@v2
218221
with:

Diff for: scripts/reorder-search-index.mjs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { readFileSync, writeFileSync } from "node:fs";
2+
3+
async function main() {
4+
const [refPath, inputPath, outputPath = null] = process.argv.slice(2);
5+
6+
const readJson = (path) => JSON.parse(readFileSync(path, "utf-8"));
7+
const getSlug = ({ url }) => url.replace(/^\/[^/]+\/docs\//, "");
8+
9+
// Read reference (e.g. "client/build/en-us/search-index.json").
10+
const ref = readJson(refPath).map(getSlug);
11+
12+
// Read index (e.g. "client/build/de/search-index.json").
13+
const input = readJson(inputPath);
14+
15+
const getIndex = (slug) => ref.indexOf(slug);
16+
17+
const result = [];
18+
for (const [fromIndex, toIndex] of input
19+
.map(getSlug)
20+
.map(getIndex)
21+
.entries()) {
22+
result[toIndex] = input[fromIndex];
23+
}
24+
25+
writeFileSync(outputPath ?? inputPath, JSON.stringify(result), "utf-8");
26+
}
27+
28+
try {
29+
main();
30+
} catch (e) {
31+
console.error(e);
32+
if (process.env.GITHUB_ACTIONS) {
33+
console.log(`::error::${e.toString()} `);
34+
}
35+
}

0 commit comments

Comments
 (0)