From 680d28ac4b17848fc414d59c45d27cd8c682fde1 Mon Sep 17 00:00:00 2001 From: john Date: Sun, 12 Jul 2026 10:15:26 +0800 Subject: [PATCH] fix: reject missing local mindspace cover files --- scripts/check-mindspace-cover.mjs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/check-mindspace-cover.mjs b/scripts/check-mindspace-cover.mjs index 96095b6..287ed24 100644 --- a/scripts/check-mindspace-cover.mjs +++ b/scripts/check-mindspace-cover.mjs @@ -54,6 +54,17 @@ function hasCoverImageHint(html) { return true; } +function missingLocalCoverPath(htmlPath, coverMeta) { + const cover = String(coverMeta?.cover ?? coverMeta?.image ?? '').trim(); + if (!cover || /^https?:\/\//i.test(cover) || cover.startsWith('data:')) return null; + const clean = cover.split('?')[0].split('#')[0].replace(/^\.\//, ''); + if (!clean || clean.startsWith('/') || clean.includes('\\')) return null; + const base = path.dirname(htmlPath); + const target = path.resolve(base, clean); + if (target !== base && !target.startsWith(`${base}${path.sep}`)) return clean; + return fs.existsSync(target) && fs.statSync(target).isFile() ? null : clean; +} + function auditCoverHtml(htmlPath, html) { const issues = []; if (!hasMindspaceCoverMeta(html)) { @@ -76,6 +87,14 @@ function auditCoverHtml(htmlPath, html) { if (!String(coverMeta.accent ?? '').trim()) { issues.push({ level: 'warn', code: 'missing_accent', message: 'mindspace-cover 缺少 accent' }); } + const missingCover = missingLocalCoverPath(htmlPath, coverMeta); + if (missingCover) { + issues.push({ + level: 'error', + code: 'missing_cover_file', + message: `mindspace-cover 引用的本地文件不存在:${missingCover}`, + }); + } } if (!hasCoverImageHint(html)) { issues.push({