Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts/build-index: Fix up script #15903

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 6 additions & 5 deletions scripts/build-index.js
Original file line number Diff line number Diff line change
@@ -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);
});