Issue #79
Thino 页面触发 Linter 自动插入 Frontmatter 的排查与解决AI 主写
近 30 天0 次浏览0 位访客统计截至 2026-10-19 · GA4
现象
在 Obsidian 的 Thino 页面中,进入页面或按下 Cmd+S 后,输入框中会自动加上如下 frontmatter:
---
title:
published:
date:
tags: []
category:
slug:
description:
date_created: 20260603
---
最开始看起来像是 Thino 写入日记时触发了格式化,因为 Thino 的内容确实存放在日记里。
第一层原因
直接原因来自 Obsidian Linter:
lintOnSave开启。lintOnFileChange开启。insert-yaml-attributes规则开启,会插入date/tags/category/slug/published/description/title。yaml-timestamp规则开启,会补date_created。
因此,只要 Linter 认为当前文件应该被 lint,就会把这套博客 frontmatter 补进去。
为什么忽略日记目录没用
一开始尝试把 02-日记 加到 Linter 的 foldersToIgnore。这个配置本身是正确的,Linter 的匹配逻辑是:
file.path.startsWith(normalizePath(folder) + "/")
也就是说,02-日记/2026/06/2026-06-29.md 会被正确忽略。
但这个方案没有解决问题,因为 Thino 页面在 Linter 眼里不是日记文件。
真正根因
临时调试插件记录到的关键运行时状态是:
activeView.type = thino_view
activeFile.path = index.md
shouldIgnoreActiveFile = false
也就是说:
- 当前视图确实是 Thino 的
thino_view。 - 但 Obsidian/Linter 暴露出来的 active file 是根目录
index.md。 - Linter 看到的是
index.md,不是日记文件。 - 所以忽略
02-日记拦不住。
这解释了两个现象:
- 按
Cmd+S时,Linter 会 lintindex.md。 - 进入 Thino 页面时,
active-leaf-change/editor-change也可能触发 Linter 处理index.md。
最终方案
新增一个极小的本地 Obsidian 插件:
.obsidian/plugins/thino-linter-guard/
插件已发布到 GitHub:
https://github.com/KazooTTT/thino-linter-guard
插件入口:
.obsidian/plugins/thino-linter-guard/main.js
核心思路:
- 当 Obsidian 当前处在 Thino 页面时(active view 是
thino_view),把这次 Linter 判断视为“应跳过”,避免它处理 Thino 暴露出来的虚拟index.md。 - 当 Obsidian 当前处在 Thino 页面时,且执行
editor:save-file时,临时关闭 Linter,保存结束后恢复。
这样可以同时覆盖:
- 进入 Thino 页面时触发的 Linter 链路。
- 在 Thino 页面按
Cmd+S时触发的保存链路。
普通 Markdown 文件不受影响,仍然会正常走 Linter。
当前插件代码要点
patchShouldIgnoreFile() {
const linter = this.app.plugins?.plugins?.["obsidian-linter"];
if (!linter || typeof linter.shouldIgnoreFile !== "function") return;
const original = linter.shouldIgnoreFile;
const plugin = this;
const wrapped = function (file, ...args) {
if (plugin.isActiveThinoView()) return true;
return original.call(this, file, ...args);
};
linter.shouldIgnoreFile = wrapped;
}
isActiveThinoView() {
return this.app.workspace.activeLeaf?.view?.getViewType?.() === "thino_view";
}
启用方式
确保 .obsidian/community-plugins.json 中包含:
"thino-linter-guard"
修改插件后,需要重载 Thino Linter Guard 插件或重启 Obsidian。