From c1a7b154e948398931e2e344a922440f80719811 Mon Sep 17 00:00:00 2001 From: Ballonek Date: Thu, 19 Sep 2024 16:12:57 +0200 Subject: [PATCH] fix: broken links in link checker --- .github/actions/validate-docs-links/src/checker.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/actions/validate-docs-links/src/checker.ts b/.github/actions/validate-docs-links/src/checker.ts index e0d0c55e2..fbb5670df 100644 --- a/.github/actions/validate-docs-links/src/checker.ts +++ b/.github/actions/validate-docs-links/src/checker.ts @@ -161,17 +161,21 @@ async function prepareDocumentMapEntry( // Checks if the links point to existing documents function validateInternalLink(errors: Errors, href: string): void { - // /docs/api/example#heading -> ["api/example", "heading""] - const [link, hash] = href.split('#') + // Split the href into link and hash + // href could be: /reference/api/settings?utm_campaign=...#hash + const [linkWithQueryAndHash, hash] = href.split('#') + + // Remove query parameters from the link + const linkWithQuery = linkWithQueryAndHash + const link = linkWithQuery.split('?')[0] if (EXCLUDED_PATHS.includes(link)) return - if(link.startsWith('/assets')) return + if (link.startsWith('/assets')) return - // check if doc page exists + // Check if doc page exists const foundPage = documentMap.get(link.replace(/^\/+/, '')) - if (!foundPage) { errors.link.push(href) } else if (hash && !EXCLUDED_HASHES.includes(hash)) {