Skip to content

Commit b134006

Browse files
committed
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.
1 parent b09c813 commit b134006

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

scripts/filter-broken-link-warnings.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
11
const fs = require("fs");
2+
const path = require("path");
23

4+
// Paths
35
const logFile = "brokenLinks.log";
6+
const unsupportedVersionsFile = path.join(process.cwd(), "src", "pages", "unsupported-versions.mdx");
47

5-
// Read the full log file
8+
// Read unsupported versions from the MDX file.
9+
let unsupportedVersions = [];
10+
try {
11+
const mdxContent = fs.readFileSync(unsupportedVersionsFile, "utf8");
12+
// Extract unsupported version numbers (like 3.7, 3.6, etc.).
13+
unsupportedVersions = Array.from(mdxContent.matchAll(/ScalarDB (\d+\.\d+)/g), match => match[1]);
14+
} catch (err) {
15+
console.error("Error reading unsupported versions file:", err);
16+
process.exit(1);
17+
}
18+
19+
if (unsupportedVersions.length === 0) {
20+
console.log("No unsupported versions found. Exiting.");
21+
process.exit(0);
22+
}
23+
24+
// Define the prefixes to filter for broken links.
25+
const prefixes = [
26+
"- Broken link on source page path",
27+
" -> linking to "
28+
];
29+
30+
// Read the log file and filter lines based on unsupported versions.
631
fs.readFile(logFile, "utf8", (err, data) => {
732
if (err) {
833
console.error("Error reading log file:", err);
934
process.exit(1);
1035
}
1136

12-
// Define the prefixes to filter
13-
const prefixes = [
14-
"- Broken link on source page path",
15-
" -> linking to "
16-
];
17-
18-
// Filter lines that start with any of the specified prefixes
1937
const filteredLines = data
2038
.split("\n")
21-
.filter((line) => prefixes.some((prefix) => line.startsWith(prefix)));
39+
.filter((line) =>
40+
prefixes.some((prefix) => line.startsWith(prefix)) &&
41+
!unsupportedVersions.some((version) => line.includes(`/docs/${version}/`)) // Exclude unsupported versions.
42+
);
2243

23-
// Overwrite the log file with only the filtered lines
44+
// Overwrite the log file with filtered lines.
2445
fs.writeFile(logFile, filteredLines.join("\n"), "utf8", (err) => {
2546
if (err) {
2647
console.error("Error writing filtered log file:", err);

0 commit comments

Comments
 (0)