From f25ff740c989700b5231aa497029fbc6a2d3f4dc Mon Sep 17 00:00:00 2001 From: Tudor Evans Date: Tue, 18 Feb 2025 16:55:22 +0000 Subject: [PATCH 1/2] add mdx support to cli --- markdown-link-check | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/markdown-link-check b/markdown-link-check index 36d5518a..33416988 100755 --- a/markdown-link-check +++ b/markdown-link-check @@ -96,13 +96,13 @@ function commaSeparatedCodesList(value, dummyPrevious) { /** * Load all files in the rootFolder and all subfolders that end with .md */ -function loadAllMarkdownFiles(rootFolder = '.') { +function loadAllMarkdownFiles(rootFolder = '.', includeMdx = false) { const files = []; fs.readdirSync(rootFolder).forEach(file => { const fullPath = path.join(rootFolder, file); if (fs.lstatSync(fullPath).isDirectory()) { files.push(...loadAllMarkdownFiles(fullPath)); - } else if (fullPath.endsWith('.md')) { + } else if (fullPath.endsWith('.md') || (includeMdx && fullPath.endsWith('mdx'))) { files.push(fullPath); } }); @@ -127,6 +127,7 @@ function getInputs() { .option('-r, --retry', 'retry after the duration indicated in \'retry-after\' header when HTTP code is 429') .option('--reporters ', 'specify reporters to use', commaSeparatedReportersList) .option('--projectBaseUrl ', 'the URL to use for {{BASEURL}} replacement') + .option('--include-mdx', 'check links in mdx files as well as md files') .arguments('[filenamesOrDirectorynamesOrUrls...]') .action(function (filenamesOrUrls) { let filenameForOutput; @@ -148,7 +149,7 @@ function getInputs() { } } - const { ignore } = program.opts(); + const { ignore, includeMdx } = program.opts(); for (const filenameOrUrl of filenamesOrUrls) { filenameForOutput = filenameOrUrl; @@ -177,7 +178,7 @@ function getInputs() { let files = []; if (fs.statSync(filenameOrUrl).isDirectory()){ - files = loadAllMarkdownFiles(filenameOrUrl) + files = loadAllMarkdownFiles(filenameOrUrl, includeMdx) } else { files = [filenameOrUrl] } From 2a6a5a385681e7ca5a2a2bdb90ef506a5f361260 Mon Sep 17 00:00:00 2001 From: Tudor Evans Date: Wed, 19 Feb 2025 11:35:31 +0000 Subject: [PATCH 2/2] recursive mdx check --- markdown-link-check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown-link-check b/markdown-link-check index 33416988..c508f242 100755 --- a/markdown-link-check +++ b/markdown-link-check @@ -101,7 +101,7 @@ function loadAllMarkdownFiles(rootFolder = '.', includeMdx = false) { fs.readdirSync(rootFolder).forEach(file => { const fullPath = path.join(rootFolder, file); if (fs.lstatSync(fullPath).isDirectory()) { - files.push(...loadAllMarkdownFiles(fullPath)); + files.push(...loadAllMarkdownFiles(fullPath, includeMdx)); } else if (fullPath.endsWith('.md') || (includeMdx && fullPath.endsWith('mdx'))) { files.push(fullPath); }