Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Generated files
.docusaurus
.cache-loader
brokenLinks.log

# Gradle build files
.gradle
Expand Down
3 changes: 2 additions & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 52 additions & 0 deletions scripts/filter-broken-link-warnings.js
Original file line number Diff line number Diff line change
@@ -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}`);
});
});