From c02c0777adbe5bed82c1fbb1c423bf7c450f3dd5 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 9 Aug 2024 20:16:36 -0400 Subject: [PATCH] Fix some unnecessary reports of DT link replacement --- docs/warning-info.md | 9 +++++++++ src/server/create-graph.ts | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/warning-info.md b/docs/warning-info.md index 0d6e66e..8810b43 100644 --- a/docs/warning-info.md +++ b/docs/warning-info.md @@ -165,6 +165,15 @@ In this case, you can replace the link with: This property reflects the [`x`](/en-US/docs/Web/HTML/Attribute/x) attribute. ``` +Currently, this check only reports if the link to be replaced is a subpage of the original link. This ensures that if the DT links to a generic page like: + +```md +- [`x`](/en-US/docs/Web/HTML/Attributes_in_general) + - Description of `x`. +``` + +We don't lose information by replacing it. + ## Self link This rule reports links pointing to the page it's already on, including links that contain an anchor but also the full path. Some of them are generated by macros. diff --git a/src/server/create-graph.ts b/src/server/create-graph.ts index 239f16d..f371899 100644 --- a/src/server/create-graph.ts +++ b/src/server/create-graph.ts @@ -301,7 +301,8 @@ graph.forEachNode((node) => { const targetDtLink = dtIdToLink .get(url.pathname) ?.get(url.hash.slice(1)); - if (targetDtLink) { + // Only report if the link to be replaced with is a subpage + if (targetDtLink && targetDtLink.href.startsWith(url.pathname)) { report( node, "Replace DT link with real target", @@ -326,7 +327,7 @@ graph.forEachNode((node) => { } } else { const targetDtLink = dtIdToLink.get(node.id)?.get(linkTarget.slice(1)); - if (targetDtLink) { + if (targetDtLink && targetDtLink.href.startsWith(node.id)) { report( node, "Replace DT link with real target",