From 1ed26d8bb4ed0bac53e7a5ddc5767f35fa2a11ae Mon Sep 17 00:00:00 2001 From: Josh Wong <23216828+josh-wong@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:31:39 +0900 Subject: [PATCH 1/5] Create filter-broken-link-warnings.js --- scripts/filter-broken-link-warnings.js | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 scripts/filter-broken-link-warnings.js diff --git a/scripts/filter-broken-link-warnings.js b/scripts/filter-broken-link-warnings.js new file mode 100644 index 00000000..d62aa8f9 --- /dev/null +++ b/scripts/filter-broken-link-warnings.js @@ -0,0 +1,31 @@ +const fs = require("fs"); + +const logFile = "brokenLinks.log"; + +// Read the full log file +fs.readFile(logFile, "utf8", (err, data) => { + if (err) { + console.error("Error reading log file:", err); + process.exit(1); + } + + // Define the prefixes to filter + const prefixes = [ + "- Broken link on source page path", + " -> linking to " + ]; + + // Filter lines that start with any of the specified prefixes + const filteredLines = data + .split("\n") + .filter((line) => prefixes.some((prefix) => line.startsWith(prefix))); + + // Overwrite the log file with only the filtered lines + fs.writeFile(logFile, filteredLines.join("\n"), "utf8", (err) => { + if (err) { + console.error("Error writing filtered log file:", err); + process.exit(1); + } + console.log(`Filtered broken link warnings saved to ${logFile}`); + }); +}); From b2196ad0f52a371157e38fcc660a23bcff58b851 Mon Sep 17 00:00:00 2001 From: Josh Wong <23216828+josh-wong@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:53:55 +0900 Subject: [PATCH 2/5] Make all broken links show warning A list of all broken links for versions of docs still under Maintenance Support are generated in **brokenLinks.log**. To eliminate potentially redundant entries in the log, only `onBrokenLinks` is set to `warn`. --- docusaurus.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index 3091dfd1..012510bf 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -24,7 +24,8 @@ const config = { projectName: 'docs-scalardb', // Usually your repo name. onBrokenLinks: 'warn', - onBrokenMarkdownLinks: 'warn', + onBrokenMarkdownLinks: 'ignore', + onBrokenAnchors: 'ignore', // Even if you don't use internationalization, you can use this field to set // useful metadata like html lang. For example, if your site is Chinese, you From bf9f35caa2cc4cccd844fa05daaa096556c540ee Mon Sep 17 00:00:00 2001 From: Josh Wong <23216828+josh-wong@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:55:40 +0900 Subject: [PATCH 3/5] Add `brokenLinks.log` **brokenLinks.log** is for internal/local purposes, so we don't need to include it in the build files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a0bd0357..30e62f9e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ # Generated files .docusaurus .cache-loader +brokenLinks.log # Gradle build files .gradle From b09c813af53b6e79c0aef68a37e1f411a27ac98c Mon Sep 17 00:00:00 2001 From: Josh Wong <23216828+josh-wong@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:57:07 +0900 Subject: [PATCH 4/5] Add broken-link log generator to `build` command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f784947..a73952ac 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "docusaurus": "docusaurus", "start": "docusaurus start", - "build": "docusaurus build && node scripts/generate-glossary-json.js", + "build": "docusaurus build 2>&1 | tee brokenLinks.log && node scripts/filter-broken-link-warnings.js && node scripts/generate-glossary-json.js", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "clear": "docusaurus clear", From b13400631d4845b0ad81d38219aa699beed28fab Mon Sep 17 00:00:00 2001 From: Josh Wong <23216828+josh-wong@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:40:55 +0900 Subject: [PATCH 5/5] Show broken links for versions under Maintenance Support To reduce work in fixing broken links for versions that we no longer support, the script checks for broken link for versions of docs that are currently under Maintenance Support. --- scripts/filter-broken-link-warnings.js | 41 +++++++++++++++++++------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/scripts/filter-broken-link-warnings.js b/scripts/filter-broken-link-warnings.js index d62aa8f9..30624673 100644 --- a/scripts/filter-broken-link-warnings.js +++ b/scripts/filter-broken-link-warnings.js @@ -1,26 +1,47 @@ const fs = require("fs"); +const path = require("path"); +// Paths const logFile = "brokenLinks.log"; +const unsupportedVersionsFile = path.join(process.cwd(), "src", "pages", "unsupported-versions.mdx"); -// Read the full log file +// Read unsupported versions from the MDX file. +let unsupportedVersions = []; +try { + const mdxContent = fs.readFileSync(unsupportedVersionsFile, "utf8"); + // Extract unsupported version numbers (like 3.7, 3.6, etc.). + unsupportedVersions = Array.from(mdxContent.matchAll(/ScalarDB (\d+\.\d+)/g), match => match[1]); +} catch (err) { + console.error("Error reading unsupported versions file:", err); + process.exit(1); +} + +if (unsupportedVersions.length === 0) { + console.log("No unsupported versions found. Exiting."); + process.exit(0); +} + +// Define the prefixes to filter for broken links. +const prefixes = [ + "- Broken link on source page path", + " -> linking to " +]; + +// Read the log file and filter lines based on unsupported versions. fs.readFile(logFile, "utf8", (err, data) => { if (err) { console.error("Error reading log file:", err); process.exit(1); } - // Define the prefixes to filter - const prefixes = [ - "- Broken link on source page path", - " -> linking to " - ]; - - // Filter lines that start with any of the specified prefixes const filteredLines = data .split("\n") - .filter((line) => prefixes.some((prefix) => line.startsWith(prefix))); + .filter((line) => + prefixes.some((prefix) => line.startsWith(prefix)) && + !unsupportedVersions.some((version) => line.includes(`/docs/${version}/`)) // Exclude unsupported versions. + ); - // Overwrite the log file with only the filtered lines + // Overwrite the log file with filtered lines. fs.writeFile(logFile, filteredLines.join("\n"), "utf8", (err) => { if (err) { console.error("Error writing filtered log file:", err);