Loading...

Loading...

Writing & Wiki Guide

This page collects how to write blog posts and Wiki pages, the multi-language conventions, and the gotchas. Useful when adding or maintaining content.

How to read: every copyable example is given as a pair — Effect (what it becomes on the page / in the output) → Corresponding source/command → Output. See the result first, then copy the pattern.

1. Writing a Post

1.1 Creating a post

Effect: a new Markdown file appears under source/_posts/ with the scaffold’s front-matter skeleton already in place — you can write the body right away.

Corresponding command:

hexo new post "Post Title"
# generates source/_posts/Post Title.md (auto-lowercased at build time)

Output: the terminal prints INFO Created: ~/.../source/_posts/Post Title.md; the file lives in source/_posts/ with no subdirectory needed.

1.2 Minimal front-matter

Effect: the file is recognized as a blog post (layout: post); a card appears on the home/archive pages, and the category and tag pages can index it.

Corresponding source:

---
layout: post
title: Post Title
categories:
  - Category Name
tags:
  - tag1
---

Output: a /posts/<abbrlink>/ page is generated, and matching entries appear under public/categories/ and public/tags/.

Other common fields:

FieldPurposeNotes
keywordsSEO keywordse.g. 'keyword1, keyword2'
excerptPost summaryShown on listing pages
imgPost cover image (shown on homepage cards)e.g. /medias_webp/cover/xxx.webp
topPin to toptrue to pin
hideFully hideNot in homepage list, not in carousel
coverEnter homepage carouselIneffective when hide: true
coverImgCustom carousel imageTakes priority over the default
tocTable of contentsfalse to disable
tochideHide the TOC sidebar by defaulttrue hides but allows expanding
mathjaxLoad MathJax for math formulastrue to enable
mermaidLoad Mermaid for diagramstrue to enable
echartsLoad EChartstrue to enable
commentsEnable commentsfalse to disable
commentSpecify comment enginee.g. waline; false disables
passwordPost encryption passwordFor per-post encryption
reprintPolicyCopyright policye.g. cc_by_nc_sa

Full field reference (23 fields) see Directory Structure & Content Management §4.

Effect: the post URL is fixed at /posts/<abbrlink>/ (e.g. /posts/13894dce/) and doesn’t change when the title changes; hand-editing abbrlink makes the old link 404 immediately.

Corresponding command (view the current value):

grep -m1 '^abbrlink' source/_posts/<filename>.md

Output:

abbrlink: 13894dce

The permalink format is posts/:abbrlink/ (e.g. /posts/13894dce/). abbrlink is generated by the hexo-abbrlink plugin and written into front-matter (since writeback: false it is no longer written back and the field is fixed). Never hand-edit the abbrlink of an existing post — it permanently breaks the link.

1.4 Content syntax

Effect: container syntax like ::: tip renders as a colored notice block (not plain text); the same content can also be produced with Markdown/tag syntax and yields the matching component.

Corresponding source:

::: tip
This is a tip notice block.
:::

Output: the HTML becomes a container block such as <div class="tip">…</div>, displayed as a colored notice box.

Posts and Wiki pages use the same Markdown renderer (hexo-renderer-markdown-it), supporting all markdown-it plugins and matery’s 14 custom tag plugins. For syntax details see “Markdown Syntax Extensions” and “Content Tag Plugins”.

2. Wiki Frontmatter

Directory convention: each wiki sub-site lives under source/{wiki}/ (e.g. source/tutorial/); the English version lives under source/en/{wiki}/ (e.g. source/en/tutorial/).

Effect: the page uses the wiki layout (three columns + sidebar) and joins the sidebar tree of the specified wiki sub-site.

Corresponding source:

---
title: Page Title
layout: wiki        # required: wiki layout (3-column + sidebar)
wiki: tutorial      # required: wiki sub-site (docs / api / tutorial)
---

Output: visiting /tutorial/<path> yields the page with a sidebar; if wiki doesn’t match, the sidebar can’t find the current page.

English versions must also add lang: en (otherwise sidebar links fall back to the Chinese path):

Effect: sidebar links on the English page carry the /en/ prefix and point at the English version; without it the sidebar still points at the Chinese path.

Corresponding source:

---
title: Page Title
layout: wiki
wiki: tutorial
lang: en            # required for English pages
---

Output: /en/tutorial/... is generated at build time, with sidebar links prefixed /en/.

Other optional fields are the same as blog posts (toc / mathjax / mermaid / echarts / closeAutoTocNum / comment etc.). Wiki pages also support disabling comments via front-matter comment: false (handled uniformly by post-filter.js).

Wiki pages support the same Markdown syntax as blog posts:

  • All markdown-it plugins: emoji / abbr / footnote / task lists / tables / containers / math ($...$) etc.
  • 14 matery tag plugins: `{% note %}`, `{% tabs %}`, `{% timeline %}`, `{% mermaid %}`, `{% button %}`, `{% label %}`, `{% groupimage %}`, `{% wechat_dialog %}`, `{% cardurl %}` etc.
  • Container syntax (:::): ::: tip / ::: warning / ::: note / ::: info / ::: attention / ::: error / ::: hint (rendered as colored notice blocks)

3. Multi-language Support

3.1 Wiki directory structure

Effect: a page exists as two files (Chinese and English), each generating its own URL after build; Chinese has no prefix, English lives under /en/.

Corresponding source (directory layout):

source/tutorial/guide/writing.md     # Chinese (default lang, no prefix)
source/en/tutorial/guide/writing.md  # English (/en/ prefix, must include lang: en)

Output: two files, public/tutorial/guide/writing.html and public/en/tutorial/guide/writing.html (measured: the output is .html, not a directory).

3.2 URL rules

Effect: each language has its own stable path; switching languages only changes the prefix.

Corresponding output:

LanguageURL
Chinese (default)/tutorial/guide/writing (no prefix)
English/en/tutorial/guide/writing (/en/ prefix)

3.3 Fallback mechanism

Effect: visiting /en/... — shows English if an English version exists; otherwise shows the Chinese content with a top banner (“This page has no en version yet, showing default language content”) plus noindex to prevent SEO duplication.

Corresponding source: source/en/{wiki}/{page}.md — just drop the new translation in as a source file, no config change needed.

  • English version exists (a matching file under source/en/) → /en/... shows English
  • No English version → /en/... falls back to the Chinese content + top banner, with noindex
  • Translation source convention: source/en/{wiki}/{page}.md

3.4 Writing tips

Effect: following the four rules below means a new page gets a sidebar entry, language switching doesn’t break, and translation keys don’t leak as raw text.

Corresponding practice:

  1. Default language (Chinese) first: write Chinese first, then add English
  2. English sidebar keys: keys in source/_data/{wiki}-sidebar.yml use English snake_case (e.g. getting_started), while display text goes through languages/*.yml translations
  3. Internal links: use absolute paths + .html in body text (e.g. /tutorial/guide/writing.html) — the language prefix is added automatically, avoiding relative-path misplacement
  4. After adding a wiki page: update source/_data/{wiki}-sidebar.yml with a sidebar entry

Output: the sidebar shows the new entry; body links under /en/tutorial/... automatically become /en/tutorial/....

Note: source/_data/{wiki}-sidebar.yml is this theme’s sidebar convention — most Hexo blogs maintain their sidebar in the theme config or templates, whereas this theme keeps one data file per wiki under _data/ for easier separate management.

3.5 Post translation versions

Effect: the same post generates two URLs (Chinese /posts/<abbrlink>/ and English /en/posts/<abbrlink>/), and the language switcher can jump between the two.

Directory convention: translation files go under source/{lang}/_posts/ (e.g. source/en/_posts/), with the SAME filename as the Chinese original.

Corresponding source (translation file front-matter):

---
layout: post
title: Post Title (English)
abbrlink: 13894dce      # must match the Chinese original
lang: en
categories:
  - Category Name
tags:
  - tag1
  - tag2
---

Output: public/en/posts/13894dce/index.html.

PointDetails
File locationsource/en/_posts/{same name as Chinese}.md
abbrlinkmust match the Chinese original, otherwise the two versions cannot be linked
lang fieldmust add lang: en
Build outputautomatically generates the /en/posts/{abbrlink}/ path

abbrlink is generated by the hexo-abbrlink plugin on first build and written into front-matter (since writeback: false it is no longer written back and the field is fixed). Never hand-edit the abbrlink of an existing post.

4. Heading Numbering Gotcha (Important)

Effect: the default CSS auto-numbers h2–h6 (1., 1.1, 1.1.1…); if the heading already contains a hand-written number, the page shows double numbering (1. 1. Overview). With closeAutoTocNum: true only the hand-written numbers remain.

Corresponding source (front-matter of a hand-numbered page):

---
title: Page Title
layout: wiki
wiki: tutorial
closeAutoTocNum: true    # disable CSS auto-numbering to avoid double numbering
---

Output: 1. Overview shows only one level of numbering; without the field it renders as 1. 1. Overview.

  • Theme CSS auto-numbering (on by default): automatically numbers h2-h6
  • Hand-written numbering (e.g. ## 1. Overview, ### 1.1 Background) double-numbers with CSS auto-numbering
  • Hand-numbered pages must set closeAutoTocNum: true (frontmatter) to disable CSS auto-numbering
  • Pages without hand-written numbering should not set that field (let CSS auto-number)

5. Verification

Effect: confirm item by item that the build output matches expectations — both language versions exist, untranslated pages show the fallback banner, and English page links don’t fall back.

Corresponding command:

# check the output after a local build
ls public/tutorial/guide/writing.html
ls public/en/tutorial/guide/writing.html

Output: both paths exist (ls reports no error), meaning both versions were generated.

  • Local build: after npm run build, visit /tutorial/xxx and /en/tutorial/xxx and confirm both versions render correctly
  • Multi-language: add a test page under source/en/tutorial/ with proper front-matter and confirm /en/tutorial/<name> shows English; then visit an untranslated page and confirm it shows the default-language content plus the top fallback banner
  • English lang: en: confirm every source/en/tutorial/**/*.md includes lang: en, otherwise sidebar links fall back to the Chinese path (/docs/ instead of /en/docs/)
  • Sidebar translations: for each language you enabled, check that the matching languages/*.yml has sidebar.tutorial.* entries, so the sidebar never shows raw keys
Comments
Data Loading...