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 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 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", diff --git a/scripts/filter-broken-link-warnings.js b/scripts/filter-broken-link-warnings.js new file mode 100644 index 00000000..30624673 --- /dev/null +++ b/scripts/filter-broken-link-warnings.js @@ -0,0 +1,52 @@ +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 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); + } + + const filteredLines = data + .split("\n") + .filter((line) => + prefixes.some((prefix) => line.startsWith(prefix)) && + !unsupportedVersions.some((version) => line.includes(`/docs/${version}/`)) // Exclude unsupported versions. + ); + + // 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); + process.exit(1); + } + console.log(`Filtered broken link warnings saved to ${logFile}`); + }); +});