update at 2025-09-22 21:02:14

This commit is contained in:
douboer
2025-09-22 21:02:14 +08:00
parent b70d02fb84
commit 855d06e727
3 changed files with 52 additions and 9 deletions

View File

@@ -373,10 +373,26 @@ export class ArticleRender implements MDRendererCallback {
if (fmAuthor) res.author = fmAuthor;
res.digest = this.getFrontmatterValue(frontmatter, keys.digest);
res.content_source_url = this.getFrontmatterValue(frontmatter, keys.content_source_url);
res.cover = this.getFrontmatterValue(frontmatter, keys.cover) || frontmatter['cover'] || frontmatter['image'];
// frontmatter 给出的 cover/image 为空字符串时视为未设置
if (typeof res.cover === 'string' && res.cover.trim() === '') {
res.cover = undefined;
if (!this.settings.ignoreFrontmatterImage) {
let fmCover = this.getFrontmatterValue(frontmatter, keys.cover) || frontmatter['cover'] || frontmatter['image'];
if (typeof fmCover === 'string') {
fmCover = fmCover.trim();
if (fmCover === '') {
fmCover = undefined;
} else if (/^https?:\/\//i.test(fmCover)) {
// 远程 URL保持原样后续逻辑支持 http 上传)
} else {
// 本地路径:可能是 /img/xxx.png 或 相对路径 foo/bar.png
const clean = fmCover.replace(/^"|"$/g, '').split('#')[0].split('?')[0];
const base = clean.split('/').pop();
if (base) {
fmCover = `![[${base}]]`;
}
}
}
res.cover = fmCover;
} else {
res.cover = undefined; // 忽略 frontmatter
}
res.thumb_media_id = this.getFrontmatterValue(frontmatter, keys.thumb_media_id);
res.need_open_comment = frontmatter[keys.need_open_comment] ? 1 : undefined;
@@ -407,11 +423,19 @@ export class ArticleRender implements MDRendererCallback {
const v = m[2].trim();
if (k === 'title' && !res.title) res.title = v;
if (k === 'author' && !res.author) res.author = v;
if ((k === 'image' || k === 'cover') && !res.cover && v) {
// image 可能是路径,取 basename
const clean = v.replace(/^"|"$/g, '').split('#')[0].split('?')[0];
const base = clean.split('/').pop();
if (base) res.cover = `![[${base}]]`;
if (!this.settings.ignoreFrontmatterImage) {
if ((k === 'image' || k === 'cover') && !res.cover && v) {
let val = v.replace(/^"|"$/g, '').trim();
if (val) {
if (/^https?:\/\//i.test(val)) {
res.cover = val; // URL
} else {
const clean = val.split('#')[0].split('?')[0];
const base = clean.split('/').pop();
if (base) res.cover = `![[${base}]]`;
}
}
}
}
}
}