跳转至

Front Matter CMS

Front Matter CMS 是一个 VS Code 扩展,在侧边面板里以表单方式编辑 Markdown 的 front matter。本仓库的配置在根目录的 frontmatter.json,扩展的本地状态在 .frontmatter/。它是可选工具,改动的仍是 content/ 下的同一批文件,不用它也能完成全部内容工作。

安装

  1. 在 VS Code 扩展市场搜索并安装 Front Matter CMS。仓库的 .vscode/extensions.json 没有把它列为推荐扩展,不会自动提示安装。
  2. 以仓库根目录作为工作区打开,扩展会读取 frontmatter.json。
  3. 打开 content/ 下任意 Markdown 文件,从活动栏的 Front Matter 图标进入面板。

当前配置

frontmatter.json 把扩展收敛成“只编辑字段和跑脚本”的最小形态,主要设置如下。

配置键 值 效果
frontMatter.framework.id hugo 按 Hugo 项目处理
frontMatter.framework.startCommand make server 扩展启动本地服务器时使用的命令
frontMatter.preview.host http://localhost:1313 预览地址
frontMatter.website.host https://jimmysong.io 线上地址
frontMatter.content.publicFolder static 静态资源目录
frontMatter.content.supportedFileTypes md 只处理 Markdown
frontMatter.global.activeMode minimal 面板只保留元数据、内容类型、操作、其他操作四个区块
frontMatter.panel.actions.disabled createContent、optimizeSlug、startStopServer、openDashboard 面板里没有新建内容、优化 slug、启停服务器、打开 Dashboard 这些按钮
frontMatter.content.autoUpdateDate false 保存时不会自动更新 lastmod
frontMatter.dashboard.openOnStart false 启动 VS Code 时不打开 Dashboard
frontMatter.panel.openOnSupportedFile false 打开 Markdown 时不自动弹出面板
frontMatter.git.enabled false 不使用扩展的 Git 同步
frontMatter.telemetry.disable true 关闭遥测

因为新建按钮被禁用,新内容仍用 hugo new 创建,见内容创建指南。lastmod 需要手工改,或用 npm run content:metadata:update-lastmod。

内容类型

frontMatter.taxonomy.contentTypes 定义了面板为每类内容显示哪些字段。所有类型都是 pageBundle: false。中英文各有一套类型,预览路径不同(中文带 zh/ 前缀),字段也略有差异。

类型 预览路径 字段
blog zh/blog/ title、date、lastmod、draft、slug、categories、tags、comment、cover、description、featured、linktitle、social_title、status
blog-en /blog/ 同 blog,没有 status,多一个 aliases
book zh/book/ title、linktitle、date、lastmod、draft、weight、description、icon、social_title、cover
podcast zh/podcast/ title、date、lastmod、draft、slug、description、categories、tags、audio_url、audio_type、audio_length、duration、episode_image_url
notice zh/notice/ title、date、draft、slug、type(默认 notice)、description、link、linktitle、cover、lastmod
notice-en notice/ title、date、draft、slug、type、description、link
slide zh/slide/ title、date、draft、slug、categories、tags、description
slide-en slide/ 同 slide,多 image、lastmod
trans zh/trans/ title、date、lastmod、draft、slug、categories、tags、comment、description、source、cover
default 无 title、date、lastmod、draft、description

用到的字段类型有 string、datetime、draft、boolean、number、image、categories、tags。面板只覆盖表中字段,其余字段(如图书的 parts、cascade、part_id、badges)直接在 YAML 里编辑。各字段的含义见内容类型指南。

配置里还留着 ai 和 ai-en 两个类型。AI 资源栏目已迁出本仓库,这两个类型没有绑定任何目录,不要使用。

目录绑定

frontMatter.content.pageFolders 把内容目录绑定到内容类型,决定打开某个文件时使用哪套字段。

目录 类型
content/zh/blog、content/zh/slide、content/zh/trans、content/zh/podcast、content/zh/notice 同名类型
content/en/blog、content/en/slide、content/en/notice blog-en、slide-en、notice-en
content/zh/book 以及其下 28 本书各一条 book

没有绑定的目录:content/en/book 和所有单页栏目(术语表、FAQ、开源工具等)。content/zh/book/ai-infra、content/zh/book/bootstrapping-microservices、content/zh/book/gpu-lab-on-kubernetes 三本书没有单独的条目。新增图书时照现有格式追加一条:

{
  "title": "book (/content/zh/book/hami-handbook)",
  "path": "[[workspace]]/content/zh/book/hami-handbook",
  "contentTypes": ["book"],
  "excludePaths": ["venv"]
}

给某类内容加字段时,在对应类型的 fields 数组里追加一项(title、name、type),中英文两个类型一起改。

自定义脚本

frontMatter.custom.scripts 在面板的操作区加了几个按钮。点击后扩展以 node <脚本> <工作区路径> <当前文件> <front matter JSON> 的形式调用,脚本针对当前打开的文章执行。

按钮 脚本 作用
Upload Images scripts/content/upload-images.js 优化当前文章目录里的图片并上传到 CDN,见图片上传
Generate Mermaid Images scripts/content/transform-mermaid.js 把 Mermaid 代码块转成 SVG,见 Mermaid 转 SVG
Localize Images scripts/content/localize-images.js 把正文里的远程图片下载到文章目录,按 f1、f2… 命名并改写引用
Publish to WeChat (Jimmy Song) scripts/content/publish-wechat-draft.js 把当前文章发布到公众号草稿箱,需要先配置公众号凭证,见微信公众号发布
Publish to WeChat (ArkSphere) scripts/content/publish-wechat-arksphere.js 同上,加 --account arksphere
Purge Cover Cache scripts/content/clear-cover-cache.js 清除当前文章 cover 图片的 CDN 缓存,需要先配置 Cloudflare 凭证
Update AI Resource scripts/ai/update-ai-resource.js 遗留按钮,对应的数据已迁出本仓库,不要使用

Upload Images 会直接写 CDN

点击 Upload Images 就会上传并改写正文中的图片地址。CDN 上传必须先得到站点所有者批准。

本地状态文件

.frontmatter/config/settings.json 是一个占位配置。.frontmatter/database/ 存放扩展维护的标签、媒体和置顶数据,已写入 .gitignore;其中 taxonomyDb.json 和 pinnedItemsDb.json 仍被 Git 跟踪,扩展改动它们时会出现在 git status 里。