fix: reject missing local mindspace cover files
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user