fix: reject missing local mindspace cover files
This commit is contained in:
@@ -54,6 +54,17 @@ function hasCoverImageHint(html) {
|
|||||||
return true;
|
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) {
|
function auditCoverHtml(htmlPath, html) {
|
||||||
const issues = [];
|
const issues = [];
|
||||||
if (!hasMindspaceCoverMeta(html)) {
|
if (!hasMindspaceCoverMeta(html)) {
|
||||||
@@ -76,6 +87,14 @@ function auditCoverHtml(htmlPath, html) {
|
|||||||
if (!String(coverMeta.accent ?? '').trim()) {
|
if (!String(coverMeta.accent ?? '').trim()) {
|
||||||
issues.push({ level: 'warn', code: 'missing_accent', message: 'mindspace-cover 缺少 accent' });
|
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)) {
|
if (!hasCoverImageHint(html)) {
|
||||||
issues.push({
|
issues.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user