From 8e829a53b5c95808c1a45e8a401acf7e05955759 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 5 May 2026 14:39:09 +0000 Subject: [PATCH] ci: Replace canonical bash command with js script that is more readable and maintainable --- .github/workflows/docsDeploy.yml | 5 ++-- .vscode/launch.json | 13 ++++++++++ docsite/canonical-replace.ts | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 docsite/canonical-replace.ts diff --git a/.github/workflows/docsDeploy.yml b/.github/workflows/docsDeploy.yml index bc04a609..92454e79 100644 --- a/.github/workflows/docsDeploy.yml +++ b/.github/workflows/docsDeploy.yml @@ -39,9 +39,8 @@ jobs: working-directory: ./docsite - name: Replace canonical - working-directory: ./docsite/build - # https://stackoverflow.com/a/74211242/1469797 - run: grep '/**" + ], + "type": "node" + }, { "name": "dev", "type": "node", diff --git a/docsite/canonical-replace.ts b/docsite/canonical-replace.ts new file mode 100644 index 00000000..ca0b9e75 --- /dev/null +++ b/docsite/canonical-replace.ts @@ -0,0 +1,42 @@ + +import fs from 'node:fs/promises'; +import path from 'node:path'; + +var args = process.argv.slice(2); + +const linkRegex = new RegExp(/ x.includes('.html')); + console.log(`Found ${files.length} files with .html extensions`); + let modifications = 0; + + await Promise.all(files.map(async (x) => { + const filePath = path.resolve(path.join(buildDir, x)); + //console.log(`Replacing at ${filePath}`); + await fs.writeFile(filePath, (await fs.readFile(filePath)).toString().replace(linkRegex, (match, capture, offset, string, groups) => { + // this may not be fully accurate since we're mutating concurrently/async + // but its a good enough signal for logging to tell if replacements happened + modifications++; + return match.replace(capture, replacement); + })); + })); + + console.log(`Done with ${modifications} replacements`); + +}()); \ No newline at end of file -- 2.51.2