Loading...

Loading...

Installation & Theme Setup

This article explains how to build a Hexo site using the matery theme from scratch and complete the basic configuration. Every step is given as Output → Corresponding command: first see what the step produces, then copy the command.

1. Create a Hexo Site

Output: the terminal first shows INFO Cloning hexo-starter ..., then INFO Install dependencies, and finishes with INFO Start blogging with Hexo!. A my-blog/ directory appears in the current directory, containing _config.yml (site config), source/ (your content), themes/ (themes — only landscape at this point) and package.json.

Corresponding command:

hexo init my-blog
cd my-blog
npm install

hexo init automatically clones hexo-starter and installs dependencies. When done, the directory already contains _config.yml (site config), source/ (content), themes/ (themes) and other basic structures.

2. Install the matery Theme

Output: themes/matery/ gains layout/, source/, scripts/, _config.yml and other directories and files, and git clone prints done.. The theme is now in place but not yet enabled — it only takes effect once §3 sets theme to matery.

Corresponding command:

git clone https://github.com/blinkfox/hexo-theme-matery.git themes/matery

This blog uses a deeply customized matery (far more features than upstream), managed as a git submodule:

git submodule add ssh://git@git.17lai.online:222/work/matery.git themes/matery

Output: the terminal prints Cloning into 'themes/matery'... and creates a .gitmodules file at the root recording the submodule URL.

The customized version is NOT compatible with upstream. Replacing it with the upstream original will lose many features — do not mix them.

3. Basic Root _config.yml Configuration

Output: after hexo server restarts, the browser tab title becomes “夜法之书”, the header subtitle shows “深度思考,深入生活”, and the page background/structure switches to matery’s styling (instead of the default landscape skin) — both the theme and the site information are in effect.

Corresponding command: edit _config.yml in the site root, save, then restart the preview:

hexo server
# Enable the matery theme
theme: matery

# Site language (matery Chinese interface)
language: zh-CN

# Site basic information
title: 夜法之书
subtitle: 深度思考,深入生活
description: 个人独立技术博客
author: appotry

The theme’s own detailed configuration lives in themes/matery/_config.yml (about 3000 lines in this blog, including menu, comments, CDN, effects, etc.). During CI builds it is overwritten by the userConfig/_config.tmp.yml template, so for daily development, edit the template file instead.

4. Create Required Pages

The matery theme menu depends on several standalone pages. Create them with hexo new page.

Output: the terminal prints INFO Created: ~/my-blog/source/about/index.md and the like for each command; source/ gains five directories — about/, tags/, categories/, friends/, galleries/ — each with an index.md. New pages do not appear in the menu automatically; you also have to register them in the theme config’s menu section.

Corresponding command:

hexo new page about
hexo new page tags
hexo new page categories
hexo new page friends
hexo new page galleries

The files generated by hexo new page only contain title and date — you must manually add the layout field (otherwise the page will not render with the corresponding layout). Once layout is added and the site regenerated, visiting /about/ shows the “about” layout rather than a post layout.

PageFilefront-matter essentials
Aboutsource/about/index.mdlayout: about
Tagssource/tags/index.mdlayout: tags
Categoriessource/categories/index.mdlayout: categories
Friendssource/friends/index.mdlayout: friends; data in source/_data/friends.yml
Galleries homesource/galleries/index.mdlayout: galleries; data in source/_data/galleries.yml

Create individual gallery pages with hexo new gallery <name> (layout: gallery; encrypted galleries can add password in front-matter).

Output: the terminal prints INFO Created: ~/my-blog/source/galleries/<name>/index.md, and you can drop photos straight into that directory.

Corresponding command:

hexo new gallery <name>

5. Install Key Dependencies

Output: when npm install finishes, the terminal prints added N packages (N varies with the dependency tree) and the corresponding packages appear in node_modules/; if a package is missing, the build fails with Cannot find module 'hexo-renderer-xxx'.

Corresponding command: add the dependencies in the table below to package.json, then run:

npm install

Below are the core dependencies used by this blog and their purposes:

DependencyPurpose
hexo-renderer-markdown-itMarkdown rendering engine (replaces the default marked), supports math formulas, Mermaid, emoji, footnotes and many other plugins
hexo-renderer-ejsRenders the theme’s EJS templates
hexo-renderer-stylusCompiles the theme’s .styl styles to CSS
hexo-abbrlinkGenerates short permanent links for posts (with permalink: posts/:abbrlink/)
hexo-deployer-gitDeploy via Git (hexo deploy pushes to GitHub etc.)
hexo-generator-sitemap / hexo-generator-baidu-sitemapGenerate sitemaps (Google / Baidu)
hexo-minifyMinify JS/CSS/HTML at build time
hexo-feedOutput RSS / Atom / JSON Feed
hexo-adminProvides the /admin visual admin panel (requires authentication)

Markdown Rendering Enhancement Plugins

hexo-renderer-markdown-it works with the following markdown-it plugins for a rich writing syntax:

  • markdown-it-mathjax3: $...$ inline / $$...$$ block math formulas
  • markdown-it-mermaid: Mermaid diagrams (with front-matter mermaid: true)
  • markdown-it-emoji, markdown-it-footnote, markdown-it-task-checkbox
  • markdown-it-container, markdown-it-admon: callout blocks / notes
  • markdown-it-ins, markdown-it-mark, markdown-it-sub, markdown-it-sup: text enhancements
  • markdown-it-multimd-table: enhanced tables (merged cells etc.)

Output: write a $E=mc^2$ and a ```mermaid code block, regenerate, and the page renders a formula and a diagram respectively; if the raw source is still shown, the corresponding plugin is missing.

Corresponding command:

hexo clean && hexo generate

Post Encryption

Post encryption is provided by the in-house HBE v4 system (replacing the hexo-blog-encrypt plugin since 2026-08-09; AES-256-GCM + PBKDF2, configured in the encrypt: section of the theme config template userConfig/_config.tmp.yml):

Output: opening a password-protected post shows a mask plus a password input box over the body; after the correct password is entered, the body decrypts and displays. If the config has not taken effect, the post is still shown in plain text.

Corresponding command: add the encrypt section to the theme config (template), then rebuild:

hexo clean && hexo generate
encrypt:
  enable: true
  tags:
    - {name: 私人, password: "your password"}

Encryption methods: front-matter password (whole post) / {% encrypt %} tag (snippet) / encrypt_password in {wiki}-sidebar.yml (whole wiki). See §8 of the “Layout & Pages” chapter.

  • Tag-based encryption: a post with an encrypted tag is encrypted automatically
  • Per-post encryption: write password: "your password" in front-matter (SHA256 form in the scaffold)

6. Local Preview & Verification

Output: first a series of generate logs such as INFO Generated: index.html (ending with Files generated in x.xs), then Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.. Opening the homepage in a browser shows the carousel/post cards, and /tags/, /categories/, /about/ each render their own layout — verification passed.

Corresponding command:

hexo clean && hexo generate   # or npm run build
hexo server                   # http://localhost:4000/

Open http://localhost:4000/ and check the homepage, tags page, categories page, about page etc. Once everything looks right, deploy via hexo deploy or push to GitHub for Vercel to build and go live.

Output: hexo deploy prints INFO Deploy done: git, and the hosting platform starts building.

Corresponding command:

hexo deploy

Troubleshooting: if pages don’t update after changing config/templates, run hexo clean then hexo generate; after modifying source/_data/*.yml data files, delete db.json before generating.

Next Steps

Comments
Data Loading...