update at 2025-09-22 18:54:59
This commit is contained in:
@@ -13,19 +13,28 @@ UI / Interaction (NotePreview)
|
||||
|
||||
Rendering & Composition (ArticleRender + MarkedParser + Extensions)
|
||||
├─ Markdown 预处理 (frontmatter 剥离 / 可选图片语法转换)
|
||||
├─ Gallery 展开 (短代码 & 块级 figure src|link → wikilink 列表)
|
||||
├─ 语法扩展 (LocalFile: wikilink 图片、文件嵌入、Excalidraw、SVG)
|
||||
├─ 行级轻语法 (applyCustomInlineBlocks: fig / ||r||g||b||y||)
|
||||
├─ 延迟元素缓存 (Mermaid / Excalidraw)
|
||||
└─ 样式注入 (主题 + 代码高亮 + 自定义 CSS)
|
||||
|
||||
Assets & Settings Layer
|
||||
├─ AssetsManager (themes, highlights, customCSS)
|
||||
└─ NMPSettings (frontmatter key 映射 / 功能开关 / 微信配置)
|
||||
└─ NMPSettings (frontmatter key 映射 / 功能开关 / 微信配置 / galleryPrePath & galleryNumPic & defaultCoverPic)
|
||||
|
||||
Resource & Media Layer
|
||||
├─ LocalImageManager (图片登记 / 上传 / 替换 / base64 嵌入)
|
||||
├─ Image Conversion (WebP -> JPG wasm)
|
||||
└─ html-to-image (Mermaid/Excalidraw 转 PNG)
|
||||
|
||||
Cover Fallback Chain (逻辑横切 Concern)
|
||||
frontmatter cover/image → 正文首本地图片 → gallery 生成列表首图 → defaultCoverPic (配置) → 空
|
||||
|
||||
Debug Logging & Throttle
|
||||
- 输出:当前文件路径、封面决策(包含 defaultCoverPic 触发)
|
||||
- 节流:同路径 3 秒内不重复打印
|
||||
|
||||
WeChat Integration Layer
|
||||
├─ Token 代理 (wxGetToken)
|
||||
├─ 草稿创建 (wxAddDraft / wxAddDraftImages)
|
||||
@@ -77,10 +86,19 @@ function resolveCover(originalMarkdown: string, fmCover?: string, thumbMediaId?:
|
||||
if (fmCover) return fmCover; // frontmatter 指定
|
||||
const body = stripFrontmatter(originalMarkdown);
|
||||
const candidates = collectImageOrder(body); // wikilink + markdown
|
||||
return candidates.length ? `![[${candidates[0]}]]` : null;
|
||||
// 若正文无本地候选再尝试 gallery 展开结果
|
||||
if (!candidates.length) {
|
||||
const galleryList = collectGalleryFirstImages(body);
|
||||
if (galleryList.length) candidates.push(galleryList[0]);
|
||||
}
|
||||
if (candidates.length) return `![[${candidates[0]}]]`;
|
||||
// 最终 defaultCoverPic 由外层 getMetadata 注入(若配置)
|
||||
return null;
|
||||
}
|
||||
```
|
||||
|
||||
Fallback 扩展:`getMetadata()` 在上述返回为空且存在 `defaultCoverPic` 时作为最终封面。
|
||||
|
||||
## 5. 图片收集策略统一要点
|
||||
- Wikilink:解析时即登记(路径 → vault file)。
|
||||
- Markdown 图片:可配置预处理转 Wikilink,以复用同一逻辑(避免重复正则后处理)。
|
||||
@@ -118,6 +136,8 @@ function resolveCover(originalMarkdown: string, fmCover?: string, thumbMediaId?:
|
||||
- 多管线并存(旧 ArticleRender vs 新 RenderService 占位)易导致图片未登记 → 需统一抽象。
|
||||
- 自动封面选取对远程图片/非图片扩展尚无过滤完备策略。
|
||||
- 正则预处理与 Marked tokenizer 逻辑耦合度高,重构时需单测保护。
|
||||
- 默认封面文件不存在导致封面缺失但用户误以为已设置 → 需未来加入存在性校验与 Notice。
|
||||
- link/caption 属性当前解析未输出 → 未来转型时注意兼容老内容。
|
||||
|
||||
## 10. 索引 / 交叉引用
|
||||
| 文档 | 内容概述 |
|
||||
|
||||
Reference in New Issue
Block a user