Skip to content

Commit

Permalink
fix(search-index): use en-US popularities for German (#12212)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
caugner authored Dec 4, 2024
1 parent a31ba5f commit 8efafd6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ jobs:
yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json
yarn tool whatsdeployed $CONTENT_TRANSLATED_ROOT --output client/build/_whatsdeployed/translated-content.json
# Sort DE search index by en-US popularity.
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
- name: Deploy with deployer
env:
# Set the CONTENT_ROOT first
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/prod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ jobs:
yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json
yarn tool whatsdeployed $CONTENT_TRANSLATED_ROOT --output client/build/_whatsdeployed/translated-content.json
# Sort DE search index by en-US popularity.
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
- name: Update search index
if: ${{ ! vars.SKIP_BUILD }}
env:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/stage-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ jobs:
yarn rari build --issues client/build/issues.json --templ-stats
# Sort DE search index by en-US popularity.
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
# SSR all pages
yarn render:html
Expand All @@ -322,6 +325,9 @@ jobs:
yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json
yarn tool whatsdeployed $CONTENT_TRANSLATED_ROOT --output client/build/_whatsdeployed/translated-content.json
# Sort DE search index by en-US popularity.
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
- name: Update search index
if: ${{ ! vars.SKIP_BUILD }}
env:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ jobs:
yarn tool whatsdeployed $CONTENT_ROOT --output client/build/_whatsdeployed/content.json
yarn tool whatsdeployed $CONTENT_TRANSLATED_ROOT --output client/build/_whatsdeployed/translated-content.json
# Sort DE search index by en-US popularity.
node scripts/reorder-search-index.mjs client/build/en-us/search-index.json client/build/de/search-index.json
- name: Authenticate with GCP
uses: google-github-actions/auth@v2
with:
Expand Down
35 changes: 35 additions & 0 deletions scripts/reorder-search-index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { readFileSync, writeFileSync } from "node:fs";

async function main() {
const [refPath, inputPath, outputPath = null] = process.argv.slice(2);

const readJson = (path) => JSON.parse(readFileSync(path, "utf-8"));
const getSlug = ({ url }) => url.replace(/^\/[^/]+\/docs\//, "");

// Read reference (e.g. "client/build/en-us/search-index.json").
const ref = readJson(refPath).map(getSlug);

// Read index (e.g. "client/build/de/search-index.json").
const input = readJson(inputPath);

const getIndex = (slug) => ref.indexOf(slug);

const result = [];
for (const [fromIndex, toIndex] of input
.map(getSlug)
.map(getIndex)
.entries()) {
result[toIndex] = input[fromIndex];
}

writeFileSync(outputPath ?? inputPath, JSON.stringify(result), "utf-8");
}

try {
main();
} catch (e) {
console.error(e);
if (process.env.GITHUB_ACTIONS) {
console.log(`::error::${e.toString()} `);
}
}

0 comments on commit 8efafd6

Please sign in to comment.