From 1a8088cae284b5ab10a6a0d7ca9e7577050372b7 Mon Sep 17 00:00:00 2001 From: Brad Veryard Date: Mon, 14 Oct 2024 22:09:10 +0800 Subject: [PATCH 1/2] fix(deadlinks): Check if public file exists --- src/node/markdownToVue.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 21ea491b9897..6cdf6d5a3d93 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -176,9 +176,15 @@ export async function createMarkdownToVueRenderFn( ) resolved = siteConfig?.rewrites.inv[resolved + '.md']?.slice(0, -3) || resolved + + const htmlFileExists = fs.existsSync(path.resolve(dir, publicDir, `${resolved}.html`)) + const checkIfPublicFileExists = fs.existsSync(path.resolve(dir, publicDir, resolved)) + if ( !pages.includes(resolved) && - !fs.existsSync(path.resolve(dir, publicDir, `${resolved}.html`)) && + ( + !htmlFileExists && !checkIfPublicFileExists + ) && !shouldIgnoreDeadLink(url) ) { recordDeadLink(url) @@ -273,15 +279,14 @@ function injectPageDataCode(tags: string[], data: PageData) { tags[existingScriptIndex] = tagSrc.replace( scriptRE, code + - (hasDefaultExport - ? `` - : `\nexport default {name:${JSON.stringify(data.relativePath)}}`) + - `` + (hasDefaultExport + ? `` + : `\nexport default {name:${JSON.stringify(data.relativePath)}}`) + + `` ) } else { tags.unshift( - `` From b4da6570f5fcc014969541abf80958cfe606c172 Mon Sep 17 00:00:00 2001 From: Brad Veryard Date: Mon, 14 Oct 2024 22:14:21 +0800 Subject: [PATCH 2/2] chore: Format file --- src/node/markdownToVue.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 6cdf6d5a3d93..361b3b0b3f23 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -177,14 +177,17 @@ export async function createMarkdownToVueRenderFn( resolved = siteConfig?.rewrites.inv[resolved + '.md']?.slice(0, -3) || resolved - const htmlFileExists = fs.existsSync(path.resolve(dir, publicDir, `${resolved}.html`)) - const checkIfPublicFileExists = fs.existsSync(path.resolve(dir, publicDir, resolved)) + const htmlFileExists = fs.existsSync( + path.resolve(dir, publicDir, `${resolved}.html`) + ) + const checkIfPublicFileExists = fs.existsSync( + path.resolve(dir, publicDir, resolved) + ) if ( !pages.includes(resolved) && - ( - !htmlFileExists && !checkIfPublicFileExists - ) && + !htmlFileExists && + !checkIfPublicFileExists && !shouldIgnoreDeadLink(url) ) { recordDeadLink(url) @@ -279,14 +282,15 @@ function injectPageDataCode(tags: string[], data: PageData) { tags[existingScriptIndex] = tagSrc.replace( scriptRE, code + - (hasDefaultExport - ? `` - : `\nexport default {name:${JSON.stringify(data.relativePath)}}`) + - `` + (hasDefaultExport + ? `` + : `\nexport default {name:${JSON.stringify(data.relativePath)}}`) + + `` ) } else { tags.unshift( - ``