From e97a9506efccd053a4361d225684555ac3218c6d Mon Sep 17 00:00:00 2001 From: ckohen Date: Mon, 18 Mar 2024 23:46:12 -0700 Subject: [PATCH] ci: check mdx components --- ci/checkLinks.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ci/checkLinks.ts b/ci/checkLinks.ts index 46b4a5357f..3498188a2b 100644 --- a/ci/checkLinks.ts +++ b/ci/checkLinks.ts @@ -75,6 +75,14 @@ function annotateResults(resultMap: Map): } } +function* concatIterables(...iterables: IterableIterator[]) { + for (const iterable of iterables) { + for (const value of iterable) { + yield value; + } + } +} + const docFiles = importDirectory(path.join(cwd, "docs"), [".md", ".mdx"]); if (!docFiles) { @@ -136,10 +144,11 @@ for (const [name, raw] of docFiles) { if (line.trim().length > 3 && line.trim().endsWith("```")) multilineCode = !multilineCode; } if (multilineCode) return; - const matches = line.matchAll(/(?.+?)\)(?!`)/g); + const componentMatches = line.matchAll(/(?:link|href)="(?!https?|mailto)(?.+?)"/g); - for (const match of matches) { - const split = match[1].split("#")[1].split("/"); + for (const match of concatIterables(markdownMatches, componentMatches)) { + const split = match.groups!.link.split("#")[1].split("/"); const page = split[0]; const anchor = split[1]; if (!validLinks.has(page)) {