Hexo Cheatsheet

I created this cheatsheet to provide a quick and easy reference for Hexo commands. Whether you’re just getting started with Hexo or are an experienced user, this guide will help you navigate the essential commands for installation, post management, deployment, and server setup. The goal is to simplify your workflow and reduce the time spent searching for the right command.

Installation

1
2
3
npm install hexo -g        # Install Hexo globally
npm update hexo -g # Update Hexo globally
hexo init # Initialize a new Hexo project

Command Overview

init

1
hexo init [folder]

Initializes a Hexo website. If no folder is provided, Hexo sets up the site in the current directory. It clones the hexo-starter template and installs dependencies using Yarn, npm, or pnpm (depending on what is available).

new

1
hexo new [layout] <title>

Creates a new post or page. If no layout is provided, Hexo uses the default layout from _config.yml. For drafts, use the draft layout.

Options:
  • -p, --path: Specify the post path.
  • -r, --replace: Replace an existing post.
  • -s, --slug: Customize the URL slug for the post.

Example:

1
hexo new page --path about/me "About me"

Creates a page at source/about/me.md with the title “About me.”

generate

1
hexo generate

Generates static files for your Hexo website.

Options:
  • -d, --deploy: Deploy the site after generation.
  • -w, --watch: Watch for file changes and regenerate.
  • -b, --bail: Stop if an error occurs during generation.
  • -f, --force: Force regeneration of all files.
  • -c, --concurrency: Set the maximum number of files to generate in parallel (default is unlimited).

publish

1
hexo publish [layout] <filename>

Publishes a draft post.

server

1
hexo server

Starts a local server (default at http://localhost:4000).

Options:
  • -p, --port: Override the default port.
  • -s, --static: Serve only static files.
  • -l, --log: Enable logging and customize the format.

deploy

1
hexo deploy

Deploys your website to the configured remote location.

Options:
  • -g, --generate: Generate static files before deployment.

render

1
hexo render <file1> [file2] ...

Renders specific files (e.g., Markdown or HTML).

Options:
  • -o, --output: Specify the output destination.

migrate

1
hexo migrate <type>

Migrates content from other blogging systems to Hexo.

clean

1
hexo clean

Cleans the cache file (db.json) and generated files (public folder).

list

1
hexo list <type>

Lists all routes or items of a specified type.

version

1
hexo version

Displays version information for Hexo.

config

1
hexo config [key] [value]

Lists or modifies the configuration in _config.yml. If only a key is specified, its value is shown; if both key and value are provided, the value is updated.


Special Modes and Options

Safe Mode

1
hexo --safe

Disables plugins and scripts. Use this if you encounter issues after installing new plugins.

Debug Mode

1
hexo --debug

Logs detailed debug information. Use this mode if you encounter problems with Hexo.

Silent Mode

1
hexo --silent

Suppresses output in the terminal.

Customize Config File Path

1
hexo --config custom.yml

Uses a custom configuration file instead of the default _config.yml. You can specify multiple config files separated by commas.

Example:

1
hexo --config custom.yml,custom2.json

Display Drafts

1
hexo --draft

Displays posts that are in the draft folder (source/_drafts).

Customize Current Working Directory (CWD)

1
hexo --cwd /path/to/cwd

Changes the current working directory to the specified path.


Shorthands

1
2
3
4
5
6
7
8
hexo n                     # hexo new
hexo p # hexo publish
hexo g # hexo generate
hexo s # hexo server
hexo d # hexo deploy

hexo s -g # hexo server with generator
hexo s -g --draft # hexo server with generator and show drafts

Server Commands

1
2
3
4
5
6
7
hexo server                # Hexo will watch files, no need to restart the server
hexo server -s # Static mode, serves the public folder and disables file watching
hexo server -p 5000 # Change port to 5000
hexo server -i 192.168.1.1 # Use custom IP address
hexo clean # Cleans the cache file (db.json) and generated files (public)
hexo g # Generates static files
hexo d # Deploys your website

Post Management

1
2
3
4
5
6
7
8
hexo new "postName"        # Create a new post (saved in _posts/postName.md)
hexo new page "pageName" # Create a new page
hexo new [layout] <title> # Create a new post with a specific layout
hexo new photo "My Gallery" # Create a new photo gallery
hexo new "Hello World" --lang tw # Create a post with a specific language

hexo new draft "New Draft" # Create a new draft (saved in _drafts/New-Draft.md)
hexo publish "New Draft" # Move draft to _posts (publish it)

TL;DR Hexo Cheatsheet

Installation

1
2
npm install hexo -g        # Install Hexo globally
hexo init # Initialize a new Hexo project

Common Commands

1
2
3
4
5
hexo new <title>           # Create a new post
hexo generate # Generate static files
hexo deploy # Deploy the site
hexo server # Start the local server
hexo clean # Clean cache and generated files

Short Commands

1
2
3
4
5
hexo n                     # hexo new
hexo p # hexo publish
hexo g # hexo generate
hexo s # hexo server
hexo d # hexo deploy

Post Management

1
2
hexo new draft <title>     # Create a new draft post
hexo publish <filename> # Publish a draft post

Deployment

1
hexo deploy --generate     # Generate and deploy

Server Options

1
2
hexo server -p 5000        # Run server on custom port
hexo server -i 192.168.1.1 # Use custom IP address

This quick reference covers the essential Hexo commands for daily use.
```