Loading...

Loading...

Hexo Introduction

What is Hexo

Hexo is a fast, simple and powerful static blog framework powered by Node.js. You only need to write in Markdown, and Hexo generates pure static HTML pages in seconds — no database, no PHP or other backend environment required. Any static hosting (GitHub Pages, Vercel, Nginx, object storage, etc.) can serve it directly.

Compared with dynamic blog systems, Hexo’s advantages:

  • Fast: static pages, no server-side rendering, CDN-friendly
  • Simple: write in Markdown, version with Git, deploy with one command
  • Powerful: a huge ecosystem of plugins and themes (this tutorial is based on the deeply customized matery theme)
  • Secure: no database, no runtime attack surface, naturally resistant to attacks

This blog (夜法之书) is built on Hexo 8.1.2 + matery theme, hosted in production by Vercel.

Environment Requirements

ComponentVersionNotes
Node.js>= 20Hexo 8.x runtime (this site uses the LTS version; package.json declares no engines field — Node >= 20 is the actual runtime requirement)
npmbundled with Node (project locks npm@9)Installed with Node.js, used to install Hexo and plugins
Gitany modern versionClone themes, deploy to Git hosting platforms

Verifying the Environment

Output: two version lines, the second followed by npm’s own update notice (only when a newer version exists). As long as Node’s major version is >= 20 and npm’s is 9, the environment is fine; a command not found means the tool is not installed or not on PATH.

v20.19.4
9.9.4

Corresponding command:

node -v    # something like v20.x
npm -v     # 9.x (project packageManager locks to npm@9)

Common Commands

CommandPurpose
hexo init [folder]Create a new site. Equivalent to cloning hexo-starter and installing dependencies
hexo new post <title>Create a post in source/_posts/ (quote the title if it contains spaces)
hexo new page <name>Create a standalone page (e.g. about, tags)
hexo new draft <title>Create a draft in source/_drafts/
hexo publish <title>Publish a draft as a regular post
hexo generateGenerate static files to public/ (-w watch for changes, -d deploy after generating)
hexo serverStart a local preview server, default http://localhost:4000/ (-p to set the port)
hexo deployDeploy the site (push to the configured Git repo, -g generates before deploying)
hexo cleanClear the cache (db.json) and the generated directory (public); recommended after changing config/plugins
hexo --safeSafe mode: skip plugins and scripts; use when debugging plugin conflicts
hexo server --draftShow drafts in preview
hexo versionShow the Hexo version

What Each Command Shows You

The table above is expanded below into Output → Corresponding command: first the feedback from the terminal/filesystem, then the command to copy.

① Create a site

Output: the terminal prints INFO Cloning hexo-starter ..., INFO Install dependencies, and finally INFO Start blogging with Hexo!; a my-blog/ directory appears with _config.yml, package.json, source/, themes/ inside.

Corresponding command:

hexo init my-blog
cd my-blog
npm install

② Create a post

Output: the terminal prints INFO Created: ~/my-blog/source/_posts/Post-title.md; opening that file shows title / date / tags and other front-matter already pre-filled from scaffolds/post.md.

Corresponding command:

hexo new post "Post title"

③ Create a standalone page

Output: the terminal prints INFO Created: ~/my-blog/source/about/index.md, and the file contains only title and date (layout must be added by hand).

Corresponding command:

hexo new page about

④ Create a draft

Output: the terminal prints INFO Created: ~/my-blog/source/_drafts/Unfinished-idea.md; it is not generated by default, so the homepage does not show it.

Corresponding command:

hexo new draft "Unfinished idea"

⑤ Publish a draft

Output: the terminal prints INFO Published: ...source/_posts/Unfinished-idea.md; the file moves from _drafts/ to _posts/ and date is written with the current time.

Corresponding command:

hexo publish "Unfinished idea"

⑥ Generate the static site

Output: the terminal lists INFO Generated: index.html, INFO Generated: posts/xxx/index.html and so on, ending with INFO Files generated in 3.2s (timing varies by machine); public/ now holds the complete HTML site.

Corresponding command:

hexo generate

⑦ Local preview

Output: the terminal prints Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.; opening that address in a browser shows the homepage. The browser refreshes automatically after you edit a file.

Corresponding command:

hexo server

⑧ Deploy

Output: the terminal prints INFO Deploying: git, INFO Clearing .deploy_git folder..., and finally INFO Deploy done: git; the hosting platform starts building.

Corresponding command:

hexo deploy

⑨ Clean the cache

Output: the terminal prints INFO Deleted database. and INFO Deleted public folder.; db.json and public/ are gone, which resolves most “my change doesn’t take effect” problems.

Corresponding command:

hexo clean

⑩ Safe mode

Output: the site still starts, but theme scripts and custom tag plugins are all skipped (pages look plainly “bare”), which tells you whether the fault comes from a plugin.

Corresponding command:

hexo --safe server

⑪ Preview drafts

Output: the same http://localhost:4000/ as a normal preview, except the homepage list now includes posts from _drafts/.

Corresponding command:

hexo server --draft

⑫ Show the version

Output: one line hexo: 8.1.2 plus environment info such as os, node, npm — paste the whole block when reporting an issue.

Corresponding command:

hexo version

Common Combinations (this project’s package.json scripts)

Output: npm run build leaves public/ ready and also builds the pagefind search index; npm run clean empties the artifacts; npm run server serves on http://localhost:4000/; npm run deploy pushes to the deploy repo.

Corresponding command:

npm run build    # hexo generate (also builds the pagefind search index)
npm run clean    # hexo clean
npm run server   # hexo server
npm run deploy   # hexo deploy

Workflow

Write (Markdown) → Generate (hexo generate) → Deploy (hexo deploy)
  1. Write: hexo new post "Post title" creates a post; edit the file under source/_posts/ in Markdown

    Output: source/_posts/Post-title.md appears with front-matter already filled in. Corresponding command: hexo new post "Post title"

  2. Preview: hexo server checks the result locally (default localhost:4000)

    Output: the browser shows pages structured like production; saving a file hot-reloads it. Corresponding command: hexo server

  3. Generate: hexo generate renders posts into static files under public/

    Output: artifacts such as public/index.html and public/posts/<abbrlink>/index.html. Corresponding command: hexo generate

  4. Deploy: hexo deploy pushes to a Git repo; or push to GitHub and let platforms like Vercel build automatically

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

Tip: after modifying _config.yml or theme config, always run hexo clean before hexo generate, otherwise the cache may cause changes not to take effect.

Next Steps

Comments
Data Loading...