Skip to content

Commit 1ed26d8

Browse files
committed
Create filter-broken-link-warnings.js
1 parent fc5c6a8 commit 1ed26d8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fs = require("fs");
2+
3+
const logFile = "brokenLinks.log";
4+
5+
// Read the full log file
6+
fs.readFile(logFile, "utf8", (err, data) => {
7+
if (err) {
8+
console.error("Error reading log file:", err);
9+
process.exit(1);
10+
}
11+
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
19+
const filteredLines = data
20+
.split("\n")
21+
.filter((line) => prefixes.some((prefix) => line.startsWith(prefix)));
22+
23+
// Overwrite the log file with only the filtered lines
24+
fs.writeFile(logFile, filteredLines.join("\n"), "utf8", (err) => {
25+
if (err) {
26+
console.error("Error writing filtered log file:", err);
27+
process.exit(1);
28+
}
29+
console.log(`Filtered broken link warnings saved to ${logFile}`);
30+
});
31+
});

0 commit comments

Comments
 (0)