From 7d3c5c37c7ad7480be285530f81f774b3744f6bf Mon Sep 17 00:00:00 2001 From: RuiNtD Date: Tue, 25 Mar 2025 19:02:49 -0600 Subject: [PATCH] scripts/build-index: Fix up script (#15903) --- scripts/README.md | 2 +- scripts/build-index.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index a2c2b6790b..ba300fc226 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -11,7 +11,7 @@ This section contains a summary of the scripts available in this directory. For - [pdf](pdf/README.md) directory contains the `render.py` and `build-pdf.sh` script and related resources to generate a PDF document of tldr-pages for a specific language or platform (or both). - [build.sh](build.sh) script builds the ZIP archives of the `pages` directory. -- [build-index.sh](build-index.sh) script builds the index of available pages. +- [build-index.js](build-index.js) script builds the index of available pages. - [check-pr.sh](check-pr.sh) script checks the page's syntax and performs various checks on the PR. - [deploy.sh](deploy.sh) script deploys the ZIP and PDF archives to the static website repository. - [send-to-bot.py](send-to-bot.py) is a Python script that sends the build or test output to tldr-bot. diff --git a/scripts/build-index.js b/scripts/build-index.js index 9ac47b9ada..de04d103cb 100644 --- a/scripts/build-index.js +++ b/scripts/build-index.js @@ -3,17 +3,18 @@ 'use strict'; const { glob } = require('glob'); +const { sep } = require('path'); function parsePlatform(pagefile) { - return pagefile.split(/\//)[1]; + return pagefile.split(sep)[1]; } function parsePagename(pagefile) { - return pagefile.split(/\//)[2].replace(/\.md$/, ''); + return pagefile.split(sep)[2].replace(/\.md$/, ''); } function parseLanguage(pagefile) { - let pagesFolder = pagefile.split(/\//)[0]; + let pagesFolder = pagefile.split(sep)[0]; return pagesFolder == 'pages' ? 'en' : pagesFolder.replace(/^pages\./, ''); } @@ -33,7 +34,7 @@ function buildPagesIndex(files) { } const targets = index[page].targets; - const exists = targets.some((t) => {return t.platform === os && t.language === language}); + const exists = targets.some((t) => t.os === os && t.language === language); if (!exists) { targets.push({os, language}) } @@ -79,6 +80,6 @@ function saveIndex(index) { process.exit(0); }).catch((err) => { console.error('ERROR building index!'); - console.error(er); + console.error(err); process.exit(1); });