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

Verify the environment:

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

Common combinations (npm scripts in this project’s package.json):

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
  2. Preview: hexo server checks the result locally (default localhost:4000)
  3. Generate: hexo generate renders posts into static files under public/
  4. Deploy: hexo deploy pushes to a Git repo; or push to GitHub and let platforms like Vercel build automatically

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...