This article is both a complete tutorial for matery theme content tag plugins and an automated test sandbox.
The theme’s natively registered tags live inthemes/matery/scripts/tags/(unified registration inindex.js).
Automated tests assert the rendered markers noted below.
1. Note
Purpose: colored callout blocks inside a post — reminders, warnings, success feedback, supplementary notes.
Learning path: minimal example → six colors → hide icon → collapsible → nested components → full parameters → boundaries & pitfalls
1.1 Minimal example
Effect (actual rendering on the page):
这是一条最简提示。结构就是:开始标签 + 内容 + 结束标签。
Corresponding source:
{% note %}
这是一条最简提示。结构就是:开始标签 + 内容 + 结束标签。
{% endnote %}With no color keyword you get a plain block with a grey border.
1.2 Six colors
Effect:
default — 普通提示
primary — 重点强调
info — 补充说明
success — 操作成功
warning — 注意事项
danger — 严重警告
Corresponding source:
{% note default %}**default** — 普通提示{% endnote %}
{% note primary %}**primary** — 重点强调{% endnote %}
{% note info %}**info** — 补充说明{% endnote %}
{% note success %}**success** — 操作成功{% endnote %}
{% note warning %}**warning** — 注意事项{% endnote %}
{% note danger %}**danger** — 严重警告{% endnote %}Color reference table:
| Keyword | Icon (Font Awesome code) | Semantics | Background source |
|---|---|---|---|
default | f0a9 (right arrow) | Plain hint | --text-color 8% mix |
primary | f055 (plus) | Key emphasis | --tagsP-purple-color 12% |
info | f05a (info) | Supplementary note | --info 8% |
success | f058 (check) | Operation succeeded | --success 8% |
warning | f06a (exclamation) | Caution | --warning 8% |
danger | f056 (cross) | Serious warning | --danger 8% |
Backgrounds are mixed with the card background via
color-mix(), so light and dark modes adapt automatically — no separate dark palette needed.
1.3 Hide the icon (no-icon)
Effect:
Corresponding source:
{% note warning no-icon %}没有左侧图标,但保留警告色边框。{% endnote %}Position is interchangeable (both are keywords, order does not matter):
{% note no-icon warning %}与上一例完全等价{% endnote %}
{% note danger no-icon %}与上一例完全等价{% endnote %}1.4 Collapsible (details)
Write a title after the keyword and you get a collapsible block (<details><summary>):
Effect:
点击展开:静态站为什么够用
静态站没有服务端,但用 构建时快照 可以获得大部分动态能力。
代价
- 内容更新需重新构建
- 搜索是本地索引,不是全文检索服务
Corresponding source:
{% note info 点击展开:静态站为什么够用 %}
静态站没有服务端,但用 **构建时快照** 可以获得大部分动态能力。
### 代价
- 内容更新需重新构建
- 搜索是本地索引,不是全文检索服务
{% endnote %}Both the title and the body go through Markdown rendering — the title can be bold, the body can hold lists, code and sub-headings.
1.5 Nesting other components
The body is rendered as Markdown, so any tag can be nested inside:
Effect:
组合示例
这一块内部放了 标签 和 粗体,还有代码 console.log(1)。
二级便签
便签可以嵌套便签,内层用内层的颜色。
Corresponding source:
{% note success 组合示例 %}
这一块内部放了 {% label primary@标签 %} 和 **粗体**,还有代码 `console.log(1)`。
{% note warning 二级便签 %}
便签可以嵌套便签,内层用内层的颜色。
{% endnote %}
{% endnote %}1.6 Full parameters
Arguments are split on spaces. At most the first 2 keywords become CSS classes; all remaining arguments are joined into the collapsible title.
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Color keyword | ❌ | none | default / primary / info / success / warning / danger |
| 2 | no-icon | ❌ | none | Hides the left icon; interchangeable with the color position |
| 2+ | Collapse title | ❌ | none | Every non-keyword argument is merged into <summary>, rendered as Markdown |
| Content | Body | ❌ | empty | Rendered as Markdown, other tags may be nested |
All allowed values:
| Keyword | Type | Description |
|---|---|---|
default | Color | Grey |
primary | Color | Purple |
info | Color | Blue |
success | Color | Green |
warning | Color | Orange |
danger | Color | Red |
no-icon | Modifier | Not a color, only hides the icon |
Alias: subnote and note register the same function — behaviour and styling are identical (it is not “secondary”).
1.7 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
First word is not a keyword (e.g. 提示内容) | No color class is added; that word becomes the collapse title → you get a colorless collapsible block, not a plain block |
| Three color keywords written | Only the first 2 are taken → class="note info success", the third becomes the collapse title |
Color misspelled (Warning with a capital) | Case-sensitive → treated as a non-keyword, becomes the title and has no color |
| Empty content | Emits an empty div, no error |
| Closing tag forgotten | The build reports unclosed tag |
| Wanted a plain block but wrote a title | Impossible — any non-keyword argument collapses the block. Move the text into the body |
Mixed with the ::: container | Different output: the tag emits <div class="note primary">, the container emits <div class="note"> (CSS distinguishes them with attribute selectors) |
1.8 Summary
- Most used:
note info/note warning— two or three words is enough - Want it collapsible: write the title right after the color
- Want a solid block without an icon: add
no-icon - Want nesting: keep writing tags in the body (remember to close them in pairs)
2. Timeline
Purpose: show version history, project milestones and personal growth in chronological order — a vertical line plus dots stringing together dated nodes.
Learning path: minimal example → colors and no title → full parameters → advanced → boundaries & pitfalls
2.1 Minimal example
One title plus one node is a complete timeline.
Effect (actual rendering on the page):
里程碑
2026-08
- 新增内容 tag 测试页
Corresponding source:
{% timeline 里程碑,green %}
<!-- timeline 2026-08 -->
- 新增内容 tag 测试页
<!-- endtimeline -->
{% endtimeline %}2.2 Common variants
Variant 1: no headline (give no arguments at all; note that you must not write only a title, or it renders class="timeline undefined")
Effect:
2026-07
- 只有节点,没有整体标题
Corresponding source:
{% timeline %}
<!-- timeline 2026-07 -->
- 只有节点,没有整体标题
<!-- endtimeline -->
{% endtimeline %}Variant 2: change the color (blue / pink / red / purple / orange / green)
Effect:
蓝色主题
2026-01
- 蓝
红色主题
2026-02
- 红
Corresponding source:
{% timeline 蓝色主题,blue %}
<!-- timeline 2026-01 -->
- 蓝
<!-- endtimeline -->
{% endtimeline %}
{% timeline 红色主题,red %}
<!-- timeline 2026-02 -->
- 红
<!-- endtimeline -->
{% endtimeline %}2.3 Full parameters
Arguments are space-joined first, then split(','), so there are only two positional parameters.
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Title | ❌ | none | Overall headline, rendered as Markdown; omitted = no headline |
| 2 | Color | ❌ | none | Pasted straight into the class name (not validated) |
| Sub-block | <!-- timeline title --> … <!-- endtimeline --> | ❌ | — | One event node; title and body both go through Markdown |
All allowed values (6 colors)
| Color | Line / dot color |
|---|---|
blue | Blue |
pink | Pink |
red | Red |
purple | Purple |
orange | Orange |
green | Green |
| omitted | Uses the .timeline default color (no color class appended) |
2.4 Advanced: Markdown and other tags inside a node
Node titles and bodies both go through Markdown rendering, so bold, links and even {% label %} work.
Effect:
主题功能演进记录
2026-08
- 新增内容 tag 测试页(note/timeline/tabs/label 等完整教程)
- 相册数据重构(galleries.yml 三种形式)
- 统一 lightGallery 图像查看库 新增
2026-07
- 评论区架构优化(comment: waline) 优化
- 修复 href=/ MIME 样式错误 修复
2020
- 创建博客,开始 matery 深度定制
Corresponding source:
{% timeline 主题功能演进记录,green %}
<!-- timeline 2026-08 -->
- 新增内容 tag 测试页(note/timeline/tabs/label 等完整教程)
- 相册数据重构(galleries.yml 三种形式)
- 统一 lightGallery 图像查看库 {% label success@新增 %}
<!-- endtimeline -->
<!-- timeline 2026-07 -->
- 评论区架构优化(comment: waline) {% label info@优化 %}
- 修复 href=/ MIME 样式错误 {% label warning@修复 %}
<!-- endtimeline -->
<!-- timeline 2020 -->
- 创建博客,开始 matery 深度定制
<!-- endtimeline -->
{% endtimeline %}2.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| Title only, no color | Emits class="timeline undefined" → no matching class, falls back to the default color (always write the color) |
Misspelled color (e.g. grey) | Class name written as-is with no CSS → falls back to the default color, no error |
<!--timeline 标题--> (no space after timeline) | Regex does not match → that node and its content vanish entirely |
No newline after --> | The opening tag requires -->\n; no match → same as above |
| Title contains a comma | Truncated by split(','); everything after the comma is lost |
| No arguments at all | No headline, empty color class, only child nodes render |
No <!-- timeline --> sub-block at all | Only the headline renders (or an empty container) |
Two-word color (light blue) | Split on the space, only the first word kept, the rest discarded |
2.6 Summary
- Most used:
{% timeline 标题,颜色 %}plus several<!-- timeline 日期 --> … <!-- endtimeline --> - No headline wanted: write no arguments at all (a title alone yields an
undefinedclass) - Change the theme color: put the color name in the 2nd argument; a typo does not error, it only falls back
- What a node can hold: all of Markdown, including inline tags like
label/button
Test assertion: the page contains the
timelinemarker + 3 time nodes.
3. Tabs
Purpose: put several pieces of content in one area and switch by clicking a title — good for comparisons, step sequences and parallel options.
Learning path: minimal example → active index / icons → full parameters → advanced → boundaries & pitfalls
3.1 Minimal example
Two tabs, the first one active by default.
Effect (actual rendering on the page):
这里是第一个标签的内容。
Corresponding source:
{% tabs 最小示例组,1 %}
<!-- tab 第一个 -->
这里是第一个标签的内容。
<!-- endtab -->
<!-- tab 第二个 -->
这里是第二个标签的内容。
<!-- endtab -->
{% endtabs %}3.2 Common variants
Variant 1: activate the second tab (the 2nd argument is 1-based)
Effect:
打开时不是它。
Corresponding source:
{% tabs 激活第二项,2 %}
<!-- tab 第一个 -->
打开时不是它。
<!-- endtab -->
<!-- tab 第二个 -->
打开时默认显示这一页。
<!-- endtab %}
{% endtabs %}Variant 2: add icons to titles (title @type:icon-name)
Effect:
- 功能全面
- 配置灵活
- 配置项多,有学习成本
Corresponding source:
{% tabs 带图标,1 %}
<!-- tab 优点 @fas:star -->
- 功能全面
- 配置灵活
<!-- endtab -->
<!-- tab 缺点 @fas:exclamation-triangle -->
- 配置项多,有学习成本
<!-- endtab -->
<!-- tab 关于 @fab:github -->
- 源码在 GitHub
<!-- endtab -->
{% endtabs %}3.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Group name | ✅ | — | Generates the container DOM id (lowercased, spaces → -); must be globally unique on the page |
| 2 | Active index | ❌ | 0 (= first active) | 1-based; 0 or omitted = first active; out of range = none active |
| Sub-block | <!-- tab title @type:icon-name --> … <!-- endtab --> | ❌ | auto-named | One tab; a space is required after tab |
| Content | Tab body | ❌ | empty | Rendered as Markdown, inline tags may be nested |
Icon prefix (type:icon-name after @)
| Form | Actual class |
|---|---|
fas:home / solid:home | fas fa-home |
far:home / regular:home | far fa-home |
fal:home / light:home | fal fa-home |
fad:home / duotone:home | fad fa-home |
fab:github | fab fa-github |
Unknown type (e.g. xxx:home) | Falls back to far |
| No icon | No <i> emitted |
3.4 Advanced: a tab body carrying full Markdown blocks
Effect:
- 功能全面:内容 tag 覆盖 10+ 插件
- 配置灵活:每个功能可独立开关
- 性能优化:懒加载 + 占位防 CLS
// 内容里照样能放代码块
const tag = 'tabs'- 配置项多,上手有学习成本
- 部分功能依赖外部 CDN
- 技术博客:代码 / 教程 / 对比
- 个人博客:相册 / 项目 / 历程
Corresponding source:
{% tabs 主题功能对比,1 %}
<!-- tab 优点 -->
- 功能全面:内容 tag 覆盖 10+ 插件
- 配置灵活:每个功能可独立开关
- 性能优化:懒加载 + 占位防 CLS
```js
// 内容里照样能放代码块
const tag = 'tabs'
```
<!-- endtab -->
<!-- tab 缺点 -->
- 配置项多,上手有学习成本
- 部分功能依赖外部 CDN
<!-- endtab -->
<!-- tab 适用场景 -->
- 技术博客:代码 / 教程 / 对比
- 个人博客:相册 / 项目 / 历程
<!-- endtab -->
{% endtabs %}3.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| Missing group name | log.error("[Tabs] Missing required tab name") → returns an empty string, the whole block disappears |
| Two groups with the same name on one page | DOM id conflict; clicking one also switches the other |
| Active index > tab count (or negative) | No tab carries active → blank first screen |
Active index written as 0 | Equivalent to omitting it (first tab active) |
<!--tab 标题--> (no space after tab) | Regex does not match → that tab and its content are lost |
| Title and icon both empty | Automatically uses “group name + index” as the title |
| Group name contains Chinese / special characters | id kept as-is (valid HTML5; CSS selectors need escaping) |
Config tag_tabs.cdn / tag_tabs.layout | cdn defaults to https://fastly.jsdelivr.net/npm/; layout defaults to ['post','page'] and is not actually read by the current render path (kept for compatibility only) |
3.6 Summary
- Most used:
{% tabs 组名 %}with several<!-- tab 标题 --> … <!-- endtab -->inside - Open tab N by default: put N in the 2nd argument (1-based;
0/omitted both mean the first) - Add an icon: append
@fas:starto the title (type:name) - The group name must be unique page-wide, otherwise clicking switches across groups
Test assertion: the page contains the
nav-tabsmarker + 3 tabs.
4. Inline label
Purpose: small colored chips inside prose — tag keywords, statuses and categories without breaking the rhythm of the sentence.
Learning path: minimal example → six colors → full parameters → advanced → boundaries & pitfalls
4.1 Minimal example
Effect (actual rendering on the page):
主要Corresponding source:
{% label primary@主要 %}★ Counter-intuitive argument order: the color comes before
@and the text after it (source:split('@'),classes=args[0],text=args[1]).
4.2 Common variants: six colors
Effect:
默认 主要 成功 信息 警告 危险Corresponding source:
{% label default@默认 %} {% label primary@主要 %} {% label success@成功 %} {% label info@信息 %} {% label warning@警告 %} {% label danger@危险 %}4.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Type | ❌ | default | One of 6 semantic colors, becomes the label-<type> class name |
| 2 | Text | ✅ | empty | Label text; when empty it logs log.warn and emits an empty label |
All allowed values (6 colors)
| Type | Semantics |
|---|---|
default | Default grey |
primary | Primary (purple / theme color) |
success | Success (green) |
info | Info (blue) |
warning | Warning (orange) |
danger | Danger (red) |
4.4 Advanced: embedding in a sentence to express status
Effect:
部署状态:已发布 灰度状态:待观察 回滚状态:已下线 —— 标签与文字混排时不换行、不破坏行高。
Corresponding source:
部署状态:{% label success@已发布 %} 灰度状态:{% label warning@待观察 %} 回滚状态:{% label danger@已下线 %} —— 标签与文字混排时不换行、不破坏行高。4.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| Type only, no text | log.warn("Label text must be defined!") → emits an empty <span> |
No @ at all | The whole string becomes the type and the text is empty → empty label + warn |
Text contains @ | Only the content between the first and second @ is kept, the rest is dropped |
Type misspelled / written in Chinese (e.g. 成功) | Class name written as-is (label-成功), no CSS match → no styling |
Text contains Markdown (**粗**) | Not rendered, the asterisks show literally |
| Text contains HTML | Inserted as-is (source does not escape); inline tags like <b> work |
| Several labels on one line | Separate with spaces, each independent |
4.6 Summary
- Most used:
{% label success@完成 %} - Remember the order: color
@text (writingtext@coloryields an unstyled label) - Multiple colors side by side: write several on one line, separated by spaces
- Do not expect Markdown: text is emitted as-is; for bold, write
<b>yourself
Test assertion: the page contains the
class="labelmarker (6 colors).
5. Button
Purpose: an action entry inside a post — jump, download, guide the reader to the next step.
Learning path: minimal example → four forms → full parameters → advanced → boundaries & pitfalls
5.1 Minimal example
Effect (actual rendering on the page):
返回首页Corresponding source:
{% button /,返回首页,home,首页 %}★ The link is the first argument (source:
url=args[0],text=args[1]); write them in the wrong order and the button points at the text.
5.2 Common variants
Effect:
访问GitHub 关于我 纯文字按钮 HexoCorresponding source:
{% button https://github.com/appotry,访问GitHub,github,GitHub %}
{% btn /about,关于我,user-circle,关于 %}
{% button /tags,纯文字按钮,,标签 %}
{% button https://hexo.io,Hexo,fa fa-book,官网 %}The four variants are: a standard button with an icon, the btn alias, a text-only button (icon left empty), and an icon written as a full fa fa-xxx class name.
5.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Link | ✅ | empty | URL / relative path; when empty it warns but still emits href="" |
| 2 | Text | ❌ | empty | Button label, Markdown is not rendered |
| 3 | Icon | ❌ | empty | FA class name; fa fa- is prepended when it does not start with fa |
| 4 | title | ❌ | empty | Hover tooltip; the attribute is omitted when empty |
| 5+ | — | ❌ | — | Silently ignored |
Alias: {% btn %} and {% button %} register the same function and are fully equivalent.
5.4 Advanced: putting a button inside a note as a guide
Effect:
Corresponding source:
{% note info 下一步 %}
读完这篇建议继续看布局篇,或者直接去标签页找同类文章:
{% button /posts/8a11fe0a/,内容 tag 篇,file-text,当前页 %}
{% button /tags,按标签浏览,tags,标签云 %}
{% endnote %}5.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| Any argument contains a comma | join(' ') then split(',') → arguments get cut apart and everything after shifts |
Icon written as home | Emits <i class="fa fa-home"> |
Icon written as fas fa-home / fa-home | Starts with fa → kept as-is (no duplicate prefix) |
| Missing link | log.warn("URL can NOT be empty.") → still renders <a href=""> (clicking returns to the current page) |
| 5th argument and beyond | Silently dropped |
| Empty title | No title="" attribute emitted |
| Text empty but icon given | An icon-only button (icon-only buttons work) |
Alias btn | Fully equivalent to button (registered by the same function) |
5.6 Summary
- Most used:
{% button 链接,文字,图标,title %} - Remember the order: link first, text second (reversed and it jumps to the wrong place)
- Text-only button: leave the icon slot empty but keep the comma
- No commas in arguments: any comma shifts the following arguments out of place
Test assertion: the page contains the
btnmarker (≥4 buttons).
6. GitHub card
Purpose: turn a repository into a clickable card (stars / forks / description) — more convincing than a bare link.
Learning path: minimal example → user card and sizes → full parameters → advanced → boundaries & pitfalls
6.1 Minimal example
Effect (actual rendering on the page):
Corresponding source:
{% githubCard user:appotry repo:hexo %}Arguments are
key:value(colon), space-separated — writingwidth=300gets the whole thing ignored.
6.2 Common variants
Variant 1: only user (renders a user card, repo area empty)
Effect:
Corresponding source:
{% githubCard user:hexojs repo:hexo %}Variant 2: explicit size
Effect:
Corresponding source:
{% githubCard user:appotry repo:hexo-theme-matery width:400 height:140 %}6.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| any | user:name | ✅ | — | GitHub username; a red error block is emitted when missing |
| any | repo:repo | ❌ | — | Repository name; omitted = user card |
| any | width:300 / width:300px | ❌ | component default | Trailing px is stripped automatically |
| any | height:150 / height:150px | ❌ | component default | Same as above |
| any | theme:theme | ❌ | default | The attribute is not emitted when the value is default |
| any | target:target | ❌ | blank | The attribute is not emitted when the value is blank |
| any | client_id:xxx | ❌ | — | OAuth client_id, raises the API rate limit |
| any | client_secret:xxx | ❌ | — | Not supported (it would leak into the front-end HTML; deliberately not implemented) |
6.4 Advanced: two repositories side by side
Effect:
Corresponding source:
{% githubCard user:appotry repo:hexo %}
{% githubCard user:hexojs repo:hexo %}The blank Markdown line between the cards makes each one its own block.
6.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
Missing user | Emits <div style="color:red">GitHub Card配置错误:缺少user参数</div>, the build does not fail |
user without repo | Renders a user card (repo area empty) |
| Value contains a space | Split into two tokens; the second has no colon → dropped |
Written as width=300 (equals sign) | No colon found → the argument is ignored |
theme:default / target:blank | Attribute not emitted, component defaults apply |
| JavaScript disabled on the page | <noscript> shows “JavaScript is required to load GitHub Cards” |
| Before the card loads | The container reserves min-height: 150px to prevent layout shift |
| Same argument written twice | The later one wins (stored in an object keyed by name) |
6.6 Summary
- Most used:
{% githubCard user:xxx repo:yyy %} - User card only: leave out
repo - Change the size:
width:400 height:140(pxoptional) - Raise the API limit: add
client_id; never writeclient_secret
Test assertion: the page contains a
github-cardor repo-name link marker.
7. Mermaid diagrams
Purpose: draw flows, sequences and class relationships as diagrams — described in text, rendered to SVG at build time.
Learning path: minimal example → three common diagrams → full parameters → advanced → boundaries & pitfalls
⚠️ Precondition: the post front-matter must have
mermaid: true, and the theme needspost.mermaid.enable: true. Without the front-matter the whole script is not emitted and the diagram is silently blank (this article declares it).
7.1 Minimal example
Effect (actual rendering on the page):
graph TD
A --> B
Corresponding source:
{% mermaid %}
graph TD
A --> B
{% endmermaid %}7.2 Common variants: the three most used diagrams
Variant 1: flowchart
Effect:
graph TD
A[构建] --> B{测试}
B -->|通过| C[部署]
B -->|失败| D[修复]
D --> B
C --> E[监控]
Corresponding source:
{% mermaid %}
graph TD
A[构建] --> B{测试}
B -->|通过| C[部署]
B -->|失败| D[修复]
D --> B
C --> E[监控]
{% endmermaid %}Variant 2: sequence diagram
Effect:
sequenceDiagram
participant U as 用户
participant S as 服务器
participant D as 数据库
U->>S: 发起请求
S->>D: 查询数据
D-->>S: 返回结果
S-->>U: 响应页面
Corresponding source:
{% mermaid %}
sequenceDiagram
participant U as 用户
participant S as 服务器
participant D as 数据库
U->>S: 发起请求
S->>D: 查询数据
D-->>S: 返回结果
S-->>U: 响应页面
{% endmermaid %}Variant 3: class diagram
Effect:
classDiagram
class 用户 {
+String 姓名
+登录()
}
class 博客 {
+String 标题
+发布()
}
用户 --> 博客
Corresponding source:
{% mermaid %}
classDiagram
class 用户 {
+String 姓名
+登录()
}
class 博客 {
+String 标题
+发布()
}
用户 --> 博客
{% endmermaid %}7.3 Full parameters
Tag arguments
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| any | Any text | ❌ | empty | Not Mermaid config — pasted verbatim into the HTML attribute slot of <code class="mermaid" …> |
In other words,
theme=darkmerely adds an HTML attribute to<code>and does not change the diagram theme; the theme comes frompost.mermaid.options.themebelow.
Config keys (theme _config.yml post.mermaid)
| Key | Allowed values | Default | Description |
|---|---|---|---|
enable | true / false | — | Master switch |
specific | true / false | true | When true, only posts with mermaid: true get the script |
options.theme | default / forest / dark / neutral / base | default | Diagram theme |
options.startOnLoad | true / false | false | The theme controls render timing itself; do not set it to true |
options.securityLevel | strict / loose / antiscript / sandbox | loose | How much HTML is allowed through |
options.flowchart.useMaxWidth | true / false | true | Whether flowcharts fill the container |
Supported diagram types: graph / flowchart, sequenceDiagram, classDiagram, stateDiagram-v2, gantt, pie, erDiagram, gitGraph, journey, mindmap, timeline, quadrantChart.
7.4 Advanced: pie chart (stable output, good for proportions)
Effect:
pie title 内容类型占比
"教程" : 45
"排障" : 30
"随笔" : 25
Corresponding source:
{% mermaid %}
pie title 内容类型占比
"教程" : 45
"排障" : 30
"随笔" : 25
{% endmermaid %}7.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
specific: true but front-matter lacks mermaid: true | The theme emits no script at all → blank diagram, no console error (the most invisible pitfall) |
theme=dark inside the tag | Only adds an HTML attribute, the diagram theme does not change |
| Diagram syntax error (indentation / arrow) | Mermaid throws a parse error; the container is left empty and shows the error graphic |
| A mermaid code fence in the body (three backticks) | Not auto-rendered (a different front-end plugin path); always use this tag |
startOnLoad: true | Conflicts with the theme’s own render timing; may double-render / flicker on first paint |
| Several diagrams on one page | Each renders independently, no interference |
| Diagrams inside encrypted fragments | Re-rendered by events.refresh() after decryption (idempotent) |
| This page’s front-matter | Already sets mermaid: true — the precondition for the examples above to render |
7.6 Summary
- Most used:
{% mermaid %}with native Mermaid syntax inside - Remember the precondition: front-matter needs
mermaid: true(whenspecific: true) - Change the theme: edit
post.mermaid.options.theme, not a tag argument - No code fences: a three-backtick mermaid block does not render; always use the tag
- A syntax error does not fail the build: that block is just blank — check the console for a parse error
Test assertion: the page contains the
class="mermaid"marker (≥3 diagrams).
8. PDF embed
Purpose: page through a PDF right inside the post — manuals, drawings and reports without leaving the page.
Learning path: minimal example → full parameters → advanced → boundaries & pitfalls
8.1 Minimal example
Effect (actual rendering on the page):
Corresponding source:
{% pdf /doc/Linux学习笔记.pdf %}8.2 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | URL | ✅ | — | PDF address; there are no other parameters such as width/height |
Automatic type detection (matched in order, first hit wins)
| Order | URL trait | Type | Render method |
|---|---|---|---|
| 1 | contains .pdf | normal | <embed>, 550px tall |
| 2 | contains drive.google.com | googledoc | <iframe>, 550px tall |
| 3 | contains www.slideshare.net | slideshare | <iframe>, 550px tall |
| 4 | anything else | normal | <embed> |
8.3 Advanced: a note in front (note + PDF combination)
Effect:
移动端提示
手机浏览器大多不支持内联 PDF,会退化成下载或空白 —— 桌面端体验完整。
Corresponding source:
{% note warning 移动端提示 %}
手机浏览器大多不支持内联 PDF,会退化成下载或空白 —— 桌面端体验完整。
{% endnote %}
{% pdf /doc/Linux学习笔记.pdf %}8.4 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
Google Drive direct link (URL contains .pdf) | Matches rule 1 first → embedded as normal, not via the Google preview |
drive.google.com/viewer?url=xxx.pdf | Also contains .pdf → classified as normal |
A slideshare link containing .pdf | Classified as normal |
| Want a different height | No parameter for it; 550px is hardcoded in 3 places, so you must edit the source or override with extra CSS |
| Empty argument | Emits <embed src="">, an empty container |
| Relative path | Resolved against the site root (e.g. /medias_webp/docs/sample.pdf) |
| Mobile browsers | Most do not support inline PDF → blank or a download prompt (not a tag issue) |
8.5 Summary
- Most used:
{% pdf /path/file.pdf %} - Remember the limit: one argument only, height hardcoded to 550px
- Want the Google preview: the URL must not contain
.pdf, otherwise it is treated as a plain embed - In-site files: write the path starting from the site root
Test assertion: the page contains a PDF-related container marker.
9. Insert fragment (insertmd)
Purpose: insert Markdown fragments from
source/_template/into the body — maintain once, reuse everywhere (series index, disclaimer, ad slot).Learning path: minimal example → with separator → full parameters → boundaries & pitfalls
9.1 Minimal example
Effect (actual rendering on the page):
系列教程
Corresponding source:
{% insertmd '_template/系列教程.md' %}9.2 Common variants: adding a separator
The 2nd argument is Markdown separator content, appended after every file (including the last one).
Effect:
系列教程
Corresponding source:
{% insertmd '_template/系列教程.md' '---' %}9.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Path | ✅ | — | Relative to source/ (not to the current post); a file or a directory both work |
| 2 | Separator | ❌ | empty | Appended after the Markdown rendering of every file (including the last) |
Behaviour details
| Item | Description |
|---|---|
| Directory mode | Passing a directory recursively collects every .md (other extensions ignored) and inserts the whole directory at once |
| Ordering | localeCompare on the full path → 第10篇 sorts before 第2篇 (lexicographic) |
| Separator | Appended once after each file, so there is also one trailing at the end |
| Renderer | Auto-detects markdown-it / marked; renders with disableNunjucks: true → Hexo tag syntax inside fragments is not executed |
| Registration | { async: true, ends: false, priority: 2 } |
| Dependency | fs-extra |
9.4 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| Path does not exist | log.error + returns an empty string → the page silently misses content, the build does not fail |
Path written relative to the post (../) | The resolution base is source/, so it is not found (silently empty) |
| Separator contains spaces | Must be quoted, otherwise only the first two segments are taken |
| Very deep directory / too many files | No depth limit; a large directory noticeably slows the build |
| Tags embedded in a fragment | Not executed (disableNunjucks), rendered as plain Markdown only |
| One file fails to render | That file returns an empty string, the others continue |
9.5 Summary
- Most used:
{% insertmd '_template/xxx.md' %}(path relative tosource/) - Want a divider: put
'---'in the 2nd argument - Want bulk insertion: pass a directory, merged in path lexicographic order
- No tags inside fragments: under
disableNunjucksthey are not executed, only plain text
Test assertion: the rendered output contains the template fragment content.
10. WeChat dialog card
Purpose: turn Q&A, support conversations and troubleshooting sessions into a chat screenshot — more direct than a blockquote.
Learning path: minimal example → multi-turn with Markdown → full parameters → advanced → boundaries & pitfalls
10.1 Minimal example
Effect (actual rendering on the page):
Corresponding source:
{% wechat_dialog %}
User: 你好
Assistant: 你好,有什么可以帮您?
{% endwechat_dialog %}★ It must be
User:/Assistant:line format, not inline arguments — writing{% wd 文字,发送者 %}renders incorrectly.
10.2 Common variants: multiple turns with Markdown
Effect:
Corresponding source:
{% wechat_dialog %}
User: 你好,我想了解 matery 主题
Assistant: 好的,有什么可以帮您?
User: 主题支持哪些功能?
Assistant: 内容 tag、相册、搜索、评论等 **20+** 功能
Assistant: 常用清单:
- 内容 tag(note / tabs / timeline)
- 相册与图库
- 本地搜索 + Pagefind
{% endwechat_dialog %}10.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| — | none | — | — | Takes no positional arguments; anything written is ignored. All content comes from the role lines inside the block |
Rules inside the block
| Form | Behaviour |
|---|---|
Starts with User: | New message: right side, green bubble, avatar 2.jpg |
Starts with Assistant: | New message: left side, grey bubble, avatar 1.jpg |
| Any other line | Appended to the current message (line breaks preserved) |
| Message body | Rendered with a dedicated new MarkdownIt() (bypasses the Hexo renderer) |
10.4 Advanced: the wd alias for a troubleshooting dialog
Effect:
Corresponding source:
{% wd %}
User: 改了样式为什么不生效?
Assistant: 先确认是不是缓存:**主题配置改动必须重新 clean 构建**。
User: clean 了还是不变
Assistant: 那看两点:
1. 配置改的是 `userConfig/_config.tmp.yml` 还是构建产物 `themes/matery/_config.yml`
2. 容器里 `pm2 restart` 不够,`db.json` 缓存还在
{% endwd %}10.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
Chinese colon User: | Not recognised (the regex requires an ASCII :) → the whole line is merged into the previous message |
Lowercase user: / assistant: | Not recognised (case-sensitive) → merged into the previous message |
| Content before the first role line | currentRole is empty → emitted as an assistant bubble |
| No role line at all in the block | All content is merged into one assistant message |
Tags such as {% note %} inside a message | Not effective (they do not go through the Hexo tag pipeline) |
| Avatars | Hardcoded to /medias_webp/avatar/1.jpg, 2.jpg; changing them requires editing the source |
| Empty block | Emits only an empty .chat-container |
10.6 Summary
- Most used: start each line with
User:/Assistant:; other lines join the current message automatically - Alias:
{% wd %}is fully equivalent - Markdown works: bold, lists and inline code all fine
- Tags do not work:
{% note %}and friends inside the block are not executed - The colon must be ASCII, and the casing must be exact
Test assertion: the page contains the WeChat dialog container marker (
.chat-container).
11. Group image
Purpose: arrange several images in a row/column grid — gallery thumbnails, comparison shots and step screenshots no longer stack one per line.
Learning path: minimal example → default layout → full parameters → advanced → boundaries & pitfalls
11.1 Minimal example
3 images with a 2-1 layout (2 on the first row, 1 on the second).
Effect (actual rendering on the page):



Corresponding source:
{% groupimage 3 2-1 %}



{% endgroupimage %}11.2 Common variants: omitting the layout
When the 2nd argument is omitted the default layout is chosen from the count (4 images → 2-2).
Effect:




Corresponding source:
{% groupimage 4 %}




{% endgroupimage %}11.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Total count | ✅ | — | Parsed with parseInt; determines the layout and per-row quota |
| 2 | Layout | ❌ | see table below | Per-row counts separated by - (3-2 = 3 then 2) |
| Content | Images | ✅ | — | Standard ![](); extracted from <img> in the rendered HTML |
Default layout (when no layout is given or validation fails)
| Count | Layout | Count | Layout |
|---|---|---|---|
| 2 | 1-1 | 7 | 3-2-2 |
| 3 | 2-1 | 8 | 3-2-3 |
| 4 | 2-2 | 9 | 3-3-3 |
| 5 | 3-2 | 10 | 3-2-2-3 |
| 6 | 3-3 | >10 | 3 per row |
Alias: {% gi %} and {% groupimage %} register the same function and are fully equivalent.
11.4 Advanced: a custom three-row layout
Effect:





Corresponding source:
{% gi 5 3-1-1 %}





{% endgi %}11.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
sum(layout) != count | Silently falls back to the default layout (no error, no warning) |
| Fewer images than the count | Later rows get empty arrays → empty rows / whitespace |
| More images than the count | Images beyond the quota are discarded |
| Count = 1 or > 10 with no layout | Falls back to “3 per row” |
Layout written as 3,2 (comma) | Only - is used to split, 3,2 parses as 3 → sum mismatch → default layout |
| Image written as a bare URL / other syntax | No <img> extracted → that image is not shown (only rendered <img> counts) |
| Count is not a number | parseInt → NaN → no default layout → 3 per row |
11.6 Summary
- Most used:
{% groupimage 数量 布局 %}...{% endgroupimage %} - Do not want to compute the layout: write only the count and use the default
- Custom: use
-separated segments like3-2-1; their sum must equal the count, otherwise it silently falls back - Images must use Markdown syntax: a bare URL is not extracted
Test assertion: the page contains the
group-imagecontainer marker.
12. URL card (cardurl)
Purpose: turn a link into a card with title/description — recommending resources or citing official docs looks better than a bare link.
Learning path: minimal example → with icon → full parameters → advanced → boundaries & pitfalls
12.1 Minimal example
Effect (actual rendering on the page):
Corresponding source:
{% cardurl [url=https://github.com/appotry/hexo] [title=夜法之书-hexo仓库] [desc=个人独立blog源码,基于hexo搭建] %}Arguments must be wrapped in square brackets (
[key=value]). Drop the brackets → the regex does not match → arguments are silently ignored and you get an empty card.
12.2 Common variants: adding a left icon
Effect:
Corresponding source:
{% cardurl [url=https://blog.17lai.site] [title=夜法之书] [desc=个人独立技术博客] [avatar=/medias_webp/avatar/1.jpg] %}12.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| any | [url=...] | ✅ | — | Target link |
| any | [title=...] | ❌ | same as url | Card title |
| any | [desc=...] | ❌ | none | Description text |
| any | [avatar=...] | ❌ | none | Left icon; no <img> emitted when omitted |
12.4 Advanced: a card list as a resource directory
Effect:
Corresponding source:
{% cardurl [url=https://github.com/appotry/hexo] [title=博客源码] [desc=Hexo 主题与内容全部开源] [avatar=/medias_webp/avatar/1.jpg] %}
{% cardurl [url=https://blog.17lai.site/tutorial/] [title=组件教程] [desc=主题全部组件的公开文档] [avatar=/medias_webp/avatar/2.jpg] %}12.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| Arguments without square brackets | The regex \[([^=]+)=(.+)\] does not match → arguments silently ignored, an empty card is emitted |
Missing desc | Shows the literal undefined (source does not null-check) |
Missing url | href="undefined", clicking goes to /undefined |
Missing title | Falls back to showing url |
| Value contains HTML/Markdown | Fully HTML-escaped (XSS protection) → shown as entities, not rendered |
Value contains ] | The regex is greedy (.+) → takes everything up to the last ] |
Empty value [desc=] | .+ requires at least 1 character → that argument is ignored |
Misspelled key ([titel=...]) | Unknown keys are ignored |
12.6 Summary
- Most used:
{% cardurl [url=...] [title=...] [desc=...] %} - Remember the brackets: not one
[key=value]can be missing - Fill in desc: without desc it shows
undefined - Add an icon:
[avatar=图片URL] - Do not put HTML in: everything is escaped and only shows as entities
Test assertion: the page contains the URL card container marker (
.card-url-wrapper).
13. Admonition container (markdown-it-container)
Purpose: write callouts with
:::syntax — no Hexo tag involved, parsed purely at the Markdown layer.Learning path: minimal example → title / five types → full parameters → advanced → boundaries & pitfalls
13.1 Minimal example
Effect (actual rendering on the page):
这是一个 warning 容器——需要注意的内容!
Corresponding source:
::: warning
这是一个 warning 容器——需要注意的内容!
:::13.2 Common variants
Variant 1: with a title (write the title on the same line after the type)
Effect:
带标题的容器:类型后同一行写标题。
Corresponding source:
::: info 可选标题
带标题的容器:类型后同一行写标题。
:::Variant 2: five types side by side
Effect:
这是一个 note 容器——补充说明。
这是一个 info 容器——信息提示。
这是一个 attention 容器——注意警示。
这是一个 error 容器——严重错误。
Corresponding source:
::: note
这是一个 note 容器——补充说明。
:::
::: info
这是一个 info 容器——信息提示。
:::
::: attention
这是一个 attention 容器——注意警示。
:::
::: error
这是一个 error 容器——严重错误。
:::13.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Type name | ✅ | — | Must be one of the 7 registered in the root _config.yml |
| 2 | Optional title | ❌ | none | Same line as the type, rendered as a heading paragraph inside the container |
| Close | ::: | ✅ | — | On its own line; missing it swallows all following content |
All allowed values (7 registered names)
| Name | Color |
|---|---|
warning | Orange |
attention | Orange (same as warning) |
note | Green |
info | Blue |
tip | Blue (same as info) |
hint | Blue (same as info) |
error | Red |
Difference from the {% note %} tag
| Aspect | ::: container | {% note %} tag |
|---|---|---|
| Parse layer | markdown-it plugin (Markdown layer) | Hexo tag plugin |
| Output | bare <div class="warning"> (no note class) | <div class="note warning"> |
| Collapsible | ❌ | ✅ (remaining arguments become the title) |
| Type extension | only the 7 registered | 6 colors + no-icon |
13.4 Advanced: lists and code inside a container
Effect:
- 先看构建日志有没有报错
- 再看浏览器控制台
- 最后确认是不是缓存
npm run clean && npm run buildCorresponding source:
::: tip 排查顺序
1. 先看构建日志有没有报错
2. 再看浏览器控制台
3. 最后确认是不是缓存
```bash
npm run clean && npm run build
```
:::13.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
Unregistered type (::: danger) | Not parsed → ::: and the text are emitted verbatim as plain paragraphs |
Forgetting the closing ::: | The entire following section is merged into the container |
| Nesting containers of the same name | markdown-it-container does not support direct same-name nesting; separate them with other content |
| Multi-line title | Only the first line is recognised as the title, the rest goes into the body |
| Style scoping | Rules hang off the .post-container descendant selector → wiki pages need <main> carrying that class (already fixed) |
Difference from !!! admon | !!! output carries .admonition + a title paragraph and closes on two blank lines |
Deprecated: the original
{% admonition %}tag form has been removed (the tag plugin no longer exists); callouts are now provided by markdown-it-container (:::) and markdown-it-admon (!!!, see the Markdown Syntax chapter).
13.6 Summary
- Most used:
::: warning…::: - Want a title: write it after the type on the same line
- Only 7 types; writing
dangeror similar is emitted verbatim - Choose one of
{% note %}and:::: use the tag for collapsibility,:::for pure Markdown - Never forget the closing
:::, or the rest of the section is swallowed
Test assertion: the page contains the
admonitioncontainer marker.
14. Encrypt fragment tag ({% encrypt %})
Purpose: password-protect a few paragraphs inside a post — each fragment has its own password, they do not affect each other, and decryption expands in place.
Learning path: minimal example → title and description → full parameters → advanced (composition + whole-wiki encryption) → boundaries & pitfalls
14.1 Minimal example
Effect (actual rendering on the page, password demo123):
Corresponding source:
{% encrypt demo123 %}
这一段在构建产物里是密文,输入密码后才展开。
{% endencrypt %}14.2 Common variants: prompt title and description
Effect (password test-secret):
Corresponding source:
{% encrypt "test-secret" "私有内容" "这是一段测试加密内容" %}
**粗体测试** 和 {% note %}内部 note 标签{% endnote %} 结尾。
SECRET-SEGMENT-TEXT-MARKER
{% endencrypt %}14.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Password | ✅ | — | Decryption password (Hexo strips the quotes automatically) |
| 2 | Title | ❌ | empty | Prompt shown above the password box |
| 3 | Description | ❌ | empty | Placeholder text for the password input |
| Content | Body | ❌ | empty | The encrypted Markdown, may contain internal tags (note/timeline etc.) |
14.4 Advanced
Advanced 1: mixed rendering of internal tags and Markdown (secondary render after decryption, after_post_render approach)
Effect (visible after decryption):
Corresponding source:
{% encrypt nested-demo "组合内容" "输入 nested-demo 查看" %}
{% note success 解密后生效 %}
片段里可以正常写 `note`、`label`,以及 **Markdown**。
{% endnote %}
{% label success@已解密 %} {% label info@二次渲染 %}
{% endencrypt %}Advanced 2: whole-wiki encryption (configure once in the sidebar data source and the entire wiki is encrypted)
Effect (description): the wiki page shows a password box on first paint; after decryption the sidebar and body expand together, and other pages of the same wiki decrypt automatically (the derived key is stored in localStorage).
Corresponding source:
# source/_data/docs-sidebar.yml
encrypt_password: "你的密码" # 必填,整站 wiki 加密
encrypt_message: 本文已加密 # 可选,提示语
encrypt_placeholder: 请输入密码 # 可选,输入框占位Test assertion: L2y (wiki encrypted page decryption) + L8 8c (encrypted wiki accessible).
14.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| No password | log.warn + outputs the plaintext as-is (no encryption at all — the most dangerous case) |
| Password/title contains spaces or Chinese punctuation | Must be quoted; otherwise it is split on spaces and only the first segment becomes the password |
Forgetting {% endencrypt %} | The build reports an unclosed tag error |
| Multiple fragments in one post | Each has its own password, independent of the others |
| Storage key | hbe.v4.segment.<page path>#<fragment index> → changing the post path or reordering fragments invalidates the decrypted state (the password is required again) |
| Forgotten password | Unrecoverable (AES-GCM + PBKDF2, no backdoor) |
| Source file | The source Markdown is still plaintext: a public repo means public content — this feature only protects the rendered output |
| Components after decryption | Code blocks / lightbox / Mermaid / layout are all re-initialised by hbe-bundle onSuccess |
Concrete re-initialisation performed for each component after decryption (these elements do not exist in the DOM before decryption, so they must be re-run):
| Component | Re-initialisation |
|---|---|
| Code blocks | codeWidget() scans the new <pre> elements and builds the toolbar |
| Image lightbox | articleInit() wraps img → lightGallery |
| Mermaid | events.refresh() re-renders (idempotent) |
| Layout | refreshLayout() re-layouts |
14.6 Summary
- Most used:
{% encrypt 密码 %}…{% endencrypt %} - Want a prompt: follow with
"标题" "输入框占位"; anything with spaces must be quoted - Tags can be embedded:
note/labelinside the fragment render normally after decryption - Forgotten password = lost content — do not keep the only copy in your head
- Whole-wiki encryption: set
encrypt_passwordindocs-sidebar.yml
Encryption unit tests
tools/tests/unit/unit-encrypt.test.js+unit/unit-encrypt2.test.jscover: AES-GCM + PBKDF2 round-trip / fragment decryption / internal note rendering / markdown bold / dk storage without password; post-decrypt runtime behaviour is verified by gate layer L2y (decrypt-refresh + container integrity).Test assertion: L2y (component initialisation after decryption).
15. Math formulas (MathJax / KaTeX dual channel)
Purpose: write LaTeX formulas in the body and have them SSR-rendered to SVG at build time — stable display without front-end JS.
Learning path: inline → block → full parameters (delimiters and engines) → advanced → boundaries & pitfalls
⚠️ Precondition: the post front-matter needs
mathjax: true(whenspecific: true); the theme’spost.math.engineselects the math engine.
15.1 Minimal example: inline formula
Effect (actual rendering on the page): the mass-energy equation
Corresponding source:
The mass-energy equation $E=mc^2$ sits right in the middle of a sentence.15.2 Common variants: block formula
Effect:
Corresponding source:
$$
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$15.3 Full parameters
Delimiter support (by engine)
| Form | mathjax engine | katex engine |
|---|---|---|
$...$ inline | ✅ | ✅ |
$$...$$ block | ✅ | ✅ |
\(...\) inline | ❌ (hardcoded in 5.x, config has no effect) | ✅ (must be a standalone block) |
\[...\] block | ❌ | ✅ (must be a standalone block) |
Engine comparison
| Item | mathjax (default) | katex |
|---|---|---|
| Build side | markdown-it-mathjax3 (Node SSR emits SVG) | markdown-it-texmath |
| Frontend | loads MathJax 3.2.2 | loads KaTeX CSS only (no JS needed) |
| Output marker | <mjx-container> | .katex |
| Switch method | post.math.engine: mathjax + keep mathjax3 | post.math.engine: katex + comment out mathjax3, enable texmath |
Configuration (root _config.yml + theme _config.yml)
# 根 _config.yml:markdown-it-mathjax3(Node 端 SSR 输出 MathJax SVG)
markdown:
plugins:
- name: markdown-it-mathjax3
options:
tex:
inlineMath: [['$', '$']]
displayMath: [['$$', '$$']]
processEscapes: true
# 主题 _config.yml:post.math 引擎(Fluid 风格,二选一)
post:
math:
enable: false # 开启后文章默认可用
specific: true # true 时需 front-matter `math: true` 才启动
engine: mathjax # Options: mathjax | katex15.4 Advanced: matrices and multi-line derivations
Effect:
Corresponding source:
$$
A = \begin{pmatrix} a & b \\ c & d \end{pmatrix},\quad
\det(A) = ad - bc
$$15.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
Writing \(...\) with the mathjax engine | Emitted verbatim, not rendered (inlineMath config is ineffective in 5.x) |
| Both engines enabled at once | Conflict (both register math_inline); only one may be used |
$ meaning money (e.g. $5) | Treated as the start of a formula → escape as \$5 |
Block $$ on the same line as text | Must be on its own line, otherwise it may be treated as inline |
specific: true but front-matter lacks mathjax: true | The theme does not inject the front-end script (the template checks page.mathjax, not math) |
\[...\] under the katex engine | Must be a standalone block; inline mixing does not work |
| Formulas inside a mind map | Go through KaTeX (hexo_markmap.features includes math) |
15.6 Summary
- Most used: inline
$...$, block$$...$$(both engines support them) - Remember the precondition: write
mathjax: truein front-matter - Escape money:
\$5, otherwise it starts a formula - Do not mix engines: mathjax and katex are mutually exclusive
- Formulas inside mind maps: configure
hexo_markmap.features: [math]
Test assertion:
tools/tests/rich-content-integration.test.js(L2o): formula pagemjx-container ≥ 10+katex ≥ 1(dual channel).
16. Mind map (markmap)
Purpose: draw an interactive mind map from a Markdown list — zoom, collapse, click links; good for mapping knowledge structures.
Learning path: minimal example → omitting the height → full parameters → advanced → boundaries & pitfalls
16.1 Minimal example
Effect (actual rendering on the page):
Corresponding source:
{% markmap 350px %}
- 主题功能测试系列
- 交互视觉篇
- 内容 tag 篇
- 自动化测试
- L1 构建验证
- L13 单测门禁
{% endmarkmap %}16.2 Common variants: no height
Effect:
Corresponding source:
{% markmap %}
- 省略高度参数
- 走 CSS 默认高度
{% endmarkmap %}16.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 | Height | ❌ | empty (CSS default) | Written verbatim into the container style="height: …"; a unit is required (350px) |
| Content | List | ✅ | — | Standard Markdown unordered list, indent with 2 spaces per level |
Config keys (root _config.yml hexo_markmap)
| Key | Allowed values | Default | Description |
|---|---|---|---|
CDN | jsdelivr / custom etc. | plugin default | Asset source; this project uses jsdelivr, then localizes via filters/markmap-localize.js |
features | math / prism / zoom (array) | [] | Formulas, code highlighting, zoom toolbar |
theme | auto etc. | plugin default | Mind map theme; auto follows light/dark |
hexo_markmap:
CDN: 'jsdelivr' # 2026-08-24: fastly.jsdelivr.net 不可达,换 cdn.jsdelivr.net
features:
- math # 脑图内公式(KaTeX)
- prism # 代码高亮
- zoom # 缩放
theme: auto16.4 Advanced: links, inline code and formulas inside nodes
Effect:
Corresponding source:
{% markmap 320px %}
- 进阶节点
- 链接 [Hexo](https://hexo.io)
- 行内代码 `npm run build`
- 公式 $a^2+b^2=c^2$
{% endmarkmap %}16.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
Height without a unit (350) | style="height: 350" is invalid → ignored by the browser, falls back to the CSS default height |
| Content is not a list | Only a root node or a render error (you must use a - list) |
| Indentation levels are wrong | Hierarchy is inferred from indentation; bad indentation attaches nodes to the wrong parent |
features missing math | Formulas display as raw LaTeX text |
hexo_markmap not configured | Uses the plugin default CDN, which may be blocked and render blank |
A page containing {% encrypt %} | Scripts switch to a serial onload chain (see below); static pages still use defer |
| Multiple markmaps on one page | Independent ids, no interference |
Coexistence with encrypted fragments (important): markmap’s four scripts (d3 / markmap-view / markmap-toolbar / init) are localized by an after_render:html filter. Pages containing {% encrypt %} use a serial onload-chain loader instead of <script defer> — because the HTML spec says a dynamically inserted <script> ignores defer (its async defaults to true). When the hbe decryption flow re-inserts them, they execute in download-completion order, exactly inverting the dependency chain (init at 1.8KB finishes first → window.markmap undefined; d3 at 280KB finishes last → markmap-view throws d3 is not defined). Static pages keep defer (parallel download, better first paint). Full root cause and debugging lessons: docs/EXPERIENCE.md §58.
16.6 Summary
- Most used:
{% markmap 350px %}+ an unordered list - The height needs a unit, otherwise it is ignored
- Hierarchy comes from indentation (2 spaces per level)
- Want formulas / code highlighting: configure
hexo_markmap.features: [math, prism] - On the same page as encrypt: the loading chain switches to serial
onload, which is expected behaviour
Test assertion:
tools/tests/rich-content-integration.test.js(L2o):.markmap svgrenders.
17. Douban card
Purpose: embed a Douban entry card for a book / movie / album (cover + rating + metadata). Since 2026-10-19 this is a local implementation built into the theme; covers are downloaded at build time and no third-party image proxy is involved.
Learning path: minimal example → movie and music → full parameters → advanced → boundaries & pitfalls
17.1 Minimal example
Effect (actual rendering on the page):
Corresponding source:
{% douban book 30376420 %}17.2 Common variants
Variant 1: movie
Effect:
Corresponding source:
{% douban movie 24745500 %}Variant 2: music
Effect:
Corresponding source:
{% douban music 35099703 %}17.3 Full parameters
| Position | Parameter | Required | Default | Description |
|---|---|---|---|---|
| 1 / 2 | type | ✅ | — | One of book / movie / music |
| 1 / 2 | id | ✅ | — | Douban entry id, must match /^\d+$/ (digits only) |
| — | Order | — | — | Decided with isNaN: the numeric token is the id, the non-numeric one is the type; order is free |
Config keys (root _config.yml doubanCard)
| Key | Allowed values | Default | Description |
|---|---|---|---|
cookie | Douban cookie string | empty | Used when an entry/endpoint requires a logged-in session |
localImages | true / false | true | Whether covers are downloaded locally; false hits Douban directly (returns 418) |
imagePath | directory path | source/medias_webp/douban | Where local covers are written |
imageUrlPrefix | URL prefix | /medias_webp/douban | Prefix used when rendering image URLs |
Localization mechanism
| Item | Description |
|---|---|
| Code | themes/matery/scripts/tags/douban-card.js |
| Dependencies | cheerio + superagent |
| Cache | DoubanCard.json (deduped by url; a hit skips Douban) |
| Cover | Downloaded at build time to source/medias_webp/douban/{type}-{id}.jpg; existing files are skipped |
| Referer | Per-type Douban referer built in (anti-hotlink requirement) |
| Dark mode | Overlay brightness(0.6) → 0.4 in dark; text uses var(--white) |
17.4 Advanced: swapping the order of type and id
isNaN decides which token is which, so {% douban 30376420 book %} and {% douban book 30376420 %} are equivalent.
Effect:
Corresponding source:
{% douban 30376420 book %}17.5 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
Type misspelled / id not numeric (e.g. 30376420a) | Promise.reject → build fails (not a silent skip) |
Order swapped ({% douban 30376420 book %}) | Works the same (isNaN decides which token is the id) |
| Douban returns 418 (hotlink protection) | Downloaded at build time with a per-type Referer, displays normally |
localImages: false | References the original Douban image directly → 418, blank cover |
| Cache hit | Does not contact Douban (builds even offline) |
| Cache file | DoubanCard.json in the project root, deduped by url; delete it to force a refresh |
| Fetch failure | Degrades to a placeholder image + placeholder text (book “见字如晤” / movie “灯影绰约” / music “乐以忘忧”) without blocking the build |
| Cover file already exists | Download skipped (faster incremental builds) |
Background: Douban has tightened hotlink protection; third-party proxies now receive 418 (all covers blank). Localizing covers means one download, usable indefinitely. See
docs/EXPERIENCE.md(douban card notes).
17.6 Summary
- Most used:
{% douban book 30376420 %}(type + numeric id) - Order is free: the non-numeric token is the type, the numeric one is the id
- The id must be numeric, otherwise the build fails outright
- Localize covers:
localImages: true(default) — do not turn it off
Appendix: Non-tag theme features
The following three items are not “article-embedded tag plugins” (§1–§17) but standalone theme-level features. They are grouped here to mark the boundary between tag and non-tag features.
18. Typewriter typing (fun_features)
Purpose: the homepage banner subtitle typed out character by character — a touch of ceremony on first paint (same source as
subtitle.typedin Interaction & Visual §3, config aggregated underfun_features.typing).Learning path: minimal example → variant → full parameters → boundaries & pitfalls
18.1 Minimal example
Effect (description): the homepage subtitle types out character by character with a blinking cursor; this article is not the homepage, so see the site homepage for the real effect (it works whenever a .typed-cursor element exists).
Corresponding source:
fun_features:
typing:
enable: true # 打字机开关
typeSpeed: 70 # 打印速度,数字越大越慢
cursorChar: "_" # 光标字符
loop: false # 是否循环播放18.2 Common variants: disable on a single page
Turn the typewriter off for this page in the post front-matter; other pages are unaffected.
Effect (description): the subtitle on that page is shown statically, with no character animation.
Corresponding source:
# 文章 front-matter
subtitle: false18.3 Full parameters
| Key | Allowed values | Default | Description |
|---|---|---|---|
fun_features.typing.enable | true / false | — | Master switch |
typeSpeed | number | theme default | Per-character interval; larger is slower |
cursorChar | any string | \| | Cursor character |
loop | true / false | false | Whether it replays after finishing |
index.slogan.api | URL | empty | Fetches the subtitle from an endpoint (falls back to text on failure) |
18.4 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| Page unchanged after a config edit | Hexo cache not invalidated → you must npm run clean && npm run build |
page.subtitle: false | Disables it only on this page; the homepage is unaffected |
index.slogan.api unreachable | Automatically falls back to the text field, never blank |
Configured together with subtitle.typed | Same source; fun_features.typing wins |
18.5 Summary
- Most used:
fun_features.typing.enable: true - Adjust the speed: a larger
typeSpeedis slower - Disable on one page: front-matter
subtitle: false - Always clean-build after a change
Test assertion:
tools/tests/rich-content-integration.test.js(L2o): the homepage.typed-cursorexists.
19. Social share (sharejs)
Purpose: a one-click share bar at the bottom of posts (Weibo / WeChat / QQ / Douban etc.), shown on post pages only.
Learning path: minimal example → platform subset → full parameters → alternative
19.1 Minimal example
Effect (description): a .social-share bar appears at the bottom of the post; the button order is determined by sites.
Corresponding source:
sharejs:
enable: true
# 支持顺序:twitter, facebook, google, qq, qzone, wechat, weibo, douban, linkedin
sites: twitter,facebook,qq,qzone,wechat,weibo,douban19.2 Common variants: keep only Chinese platforms
Effect (description): the share bar renders only the wechat,weibo,qq buttons.
Corresponding source:
sharejs:
enable: true
sites: wechat,weibo,qq19.3 Full parameters
| Key | Allowed values | Default | Description |
|---|---|---|---|
sharejs.enable | true / false | — | Master switch |
sharejs.sites | comma-separated platform names | theme default | Render order = written order |
| Available platforms | twitter / facebook / google / qq / qzone / wechat / weibo / douban / linkedin | — | Anything not in the list is not rendered |
| Render scope | page.layout == 'post' only | — | Not shown on the homepage or standalone pages |
19.4 Alternative: addthis (mutually exclusive with sharejs)
Effect (description): the share bar is replaced by the AddThis implementation, with slightly different styling from the site’s own.
Corresponding source:
addthis:
enable: false
pubid: 613a04428f842fe119.5 Summary
- Most used:
sharejs.enable: true+ asiteslist - China only:
wechat,weibo,qqis enough - Order follows the written order
- Do not enable addthis at the same time: pick one
Test assertion:
tools/tests/rich-content-integration.test.js(L2o): the.social-sharecomponent exists.
20. Live2D mascot
Purpose: a persistent Live2D model in the bottom-right corner (purely static, no PHP backend), interactive and swappable.
Learning path: minimal example → returning-visitor guard → full parameters → boundaries & pitfalls
20.1 Minimal example
Effect (description): the mascot appears in the bottom-right corner (#live2dcanvas / #waifu); it does not load on the first visit, only on the second.
Corresponding source:
live2dWidget:
enable: true20.2 Common variants: adjusting the returning-visitor threshold
Effect (description): by default it loads only when viewCount > 1; change the threshold to > 0 to load on the first visit too (at the cost of first-paint performance).
Corresponding source:
# 主题源码中的加载守卫(themes/matery 的 live2d 初始化)
# localStorage.viewCount > 1 才初始化模型20.3 Full parameters
| Key | Allowed values | Default | Description |
|---|---|---|---|
live2dWidget.enable | true / false | — | Mascot master switch |
| Model directory | static files | source/live2d/ | Cubism2 / Cubism5 dual runtime |
| Light/dark theme | follows automatically | — | Switches model/colors in dark mode |
| Returning-visitor guard | localStorage.viewCount > 1 | enabled | Does not load on first visit; performance protection |
20.4 Boundaries & pitfalls
| Case | Behaviour |
|---|---|
| Invisible on the first visit | Expected behaviour (loads only when viewCount > 1) |
Changing enable has no effect | A clean build is required (Hexo cache) |
| The model does not move | Check that source/live2d/ assets are complete (a skip_render static directory) |
| Mobile | Usually hidden to avoid covering content |
20.5 Summary
- Most used:
live2dWidget.enable: true - Refresh twice when verifying (returning-visitor guard)
- Models live in
source/live2d/; both Cubism2 and Cubism5 work - Clean-build after a config change
Test assertion:
tools/tests/rich-content-integration.test.js(L2o): after settingviewCount=3, the mascot container exists.
⚠️ Known pitfalls
Pitfall 1: double section numbering
Symptom: headings render as “1. 1. Overview” (two numbers).
Cause: theme CSS auto-numbers h2–h6 by default, which stacks on top of hand-written numbers (e.g. ## 1. Overview).
Fix: pages with hand-written numbering add closeAutoTocNum: true in front-matter; pages without hand-written numbering must not add that field.
This article already sets
closeAutoTocNum: truecorrectly.
Pitfall 5: config changes require a clean build
Symptom: after changing tag-plugin configuration (e.g. post.mermaid.enable, live2dWidget.enable, sharejs.enable), the page does not change.
Cause: Hexo’s cache does not detect configuration changes automatically.
Fix: after changing config you must run npm run clean && npm run build.
Appendix: tag plugin quick reference
| Plugin | Syntax | Key params | Frontmatter needed |
|---|---|---|---|
| note | {% note 颜色 %}内容{% endnote %} | 6 colors | no |
| timeline | {% timeline 标题,颜色 %}...{% endtimeline %} | title / color | no |
| tabs | {% tabs 名称,序号 %}...{% endtabs %} | name / index | no |
| label | {% label 颜色@文字 %} | color first, text after | no |
| button | {% button 链接,文字,图标,title %} | link first / text second | no |
| githubCard | {% githubCard user:xx repo:yy %} | user / repo | no |
| mermaid | {% mermaid %}...{% endmermaid %} | diagram type | yes (mermaid: true) |
{% pdf URL %} | URL | no | |
| insertmd | {% insertmd 'file.md' %} | filename | no |
| wechat_dialog | {% wechat_dialog %}User:/Assistant: 行{% endwechat_dialog %} | User/Assistant lines | no |
| groupimage | {% groupimage 数量 布局 %}{% endgroupimage %} | count / layout | no |
| cardurl | {% cardurl [url=xxx] %} | url / title / desc | no |
| admonition | ::: warning 内容 ::: | container :::; the original {% admonition %} tag is deprecated | no |
| encrypt | {% encrypt 密码 "标题" "简介" %}...{% endencrypt %} | password / title / description | no |
| math | $...$ / $$...$$ | mathjax3 (SSR SVG) / katex engine | yes (mathjax: true) |
| markmap | {% markmap 350px %}列表{% endmarkmap %} | height / features (math/prism/zoom) | no |
| douban | {% douban book\|movie\|music id %} | type / id order interchangeable; covers localized | no |
| typewriter | fun_features.typing | typeSpeed / cursorChar / loop | no |
| share | sharejs.sites | twitter / wechat / weibo etc. | no (post pages only) |
| Live2D | live2dWidget.enable | returning-visitor guard viewCount>1 | no |
References & credits
系列教程
Hexo 主题功能测试系列
- Hexo主题功能测试-布局与页面篇 —— 页面布局、导航、侧边栏、卡片等结构功能
- Hexo主题功能测试-交互视觉篇 —— 代码高亮、图片灯箱、动画、明暗切换等交互
- Hexo主题功能测试-内容tag篇 —— note / tabs / timeline / label / button 等 tag 插件
- Hexo主题功能测试-Markdown语法篇 —— Markdown 渲染与扩展语法
- Hexo主题功能测试-自动化测试篇 —— 主题功能的自动化测试方案

