Skip to content

Commit

Permalink
Some sidebar links have trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Jul 27, 2024
1 parent fd21f0b commit 7d4eca8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/server/create-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ graph.forEachNode((node) => {
const url = new URL(linkTarget, "https://developer.mozilla.org");
const targetNode = graph.getNode(url.pathname);
if (!targetNode) {
report(node, "Broken link to", url.pathname);
report(node, "Broken link", url.pathname);
continue;
}
if (
Expand Down Expand Up @@ -304,11 +304,13 @@ for (const node of nodes) {
if (processedSidebars.has(normalizedHTML)) continue;
const $ = load(normalizedHTML);
$("a").each((i, a) => {
const href = $(a).attr("href");
const href = $(a).attr("href")?.replace(/\/$/, "");
if (href && href.startsWith("/en-US/")) {
const targetNode = graph.getNode(href);
if (targetNode) {
unreachableViaSidebar.delete(targetNode);
} else {
report(node, "Broken sidebar link", $(a).text(), href);
}
} else {
report(node, "Bad sidebar link", $(a).text(), href);
Expand Down
4 changes: 2 additions & 2 deletions src/server/process-warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ for (const node of nodes) {
if (id === "broken_links") {
const correspondingWarning = nodeWarnings.find(
(w) =>
w.message === "Broken link to" &&
w.message === "Broken link" &&
w.data[0] === d.href.replace(/#.+/, "") &&
w.data.at(-1) !== "(and flaw)"
);
Expand Down Expand Up @@ -146,7 +146,7 @@ for (const [nodeId, baseMessages] of warningList) {
// Caused by broken macros which are reported
(
x.message === "Missing href" ||
(x.message === "Broken link to" &&
(x.message === "Broken link" &&
(missingFeatures.has(x.data[0]) ||
(noPageRec.has(x.data[0]) &&
(noPageRec.set(x.data[0], true), true)))) ||
Expand Down

0 comments on commit 7d4eca8

Please sign in to comment.