diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index d3565a012f3c..fb0559a3f755 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -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 diff --git a/.github/workflows/prod-build.yml b/.github/workflows/prod-build.yml index 0b5b0c29396f..d574a7231d20 100644 --- a/.github/workflows/prod-build.yml +++ b/.github/workflows/prod-build.yml @@ -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: diff --git a/.github/workflows/stage-build.yml b/.github/workflows/stage-build.yml index 899d3d7e6a4c..2a0d475cb36b 100644 --- a/.github/workflows/stage-build.yml +++ b/.github/workflows/stage-build.yml @@ -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 @@ -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: diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 21fe49f08a9f..1e665a62e80a 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -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: diff --git a/scripts/reorder-search-index.mjs b/scripts/reorder-search-index.mjs new file mode 100644 index 000000000000..33fef2c1819e --- /dev/null +++ b/scripts/reorder-search-index.mjs @@ -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()} `); + } +}