hexo

hexo入门

2026-05-15 #hexo

Hexo 常用命令总结

1
2
3
4
5
6
7
# Hexo 常用命令总结

## 一、初始化与安装

### 安装 Hexo CLI
```bash
npm install -g hexo-cli

创建博客项目

1
hexo init blog

进入项目目录

1
cd blog

安装依赖

1
npm install

二、启动与预览

启动本地服务器

1
hexo server

简写:

1
hexo s

默认访问:

1
http://localhost:4000

指定端口启动

1
hexo server -p 5000

启动并实时监视文件变化

1
hexo server --watch

三、文章与页面管理

新建文章

创建普通文章

1
hexo new "我的第一篇文章"

生成位置:

1
source/_posts/

创建草稿

1
hexo new draft "未完成文章"

生成位置:

1
source/_drafts/

创建页面

1
hexo new page "about"

生成位置:

1
source/about/

四、生成静态文件

生成静态网页

1
hexo generate

简写:

1
hexo g

生成目录:

1
public/

生成前清理旧文件

1
hexo generate --clean

五、部署网站

安装 Git 部署插件

1
npm install hexo-deployer-git --save

配置 _config.yml

1
2
3
4
deploy:
type: git
repo: https://github.com/用户名/仓库名.git
branch: main

部署到 GitHub Pages

生成并部署

1
hexo deploy

简写:

1
hexo d

清理 + 生成 + 部署

1
hexo clean && hexo g && hexo d

六、清理缓存

清理缓存与生成文件

1
hexo clean

会删除:

1
2
3
db.json
public/
.deploy_git/

七、Hexo 常用组合命令

本地开发常用

1
2
3
hexo clean
hexo g
hexo s

一键部署

1
hexo clean && hexo g && hexo d

八、主题相关命令

下载主题(以 Butterfly 为例)

1
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly

修改主题

编辑:

1
_config.yml

设置:

1
theme: butterfly

九、Front-matter 示例

文章顶部配置:

1
2
3
4
5
6
7
8
9
10
---
title: 我的文章
date: 2026-05-15 12:00:00
tags:
- Hexo
- Blog
categories:
- 技术
cover: https://example.com/image.png
---

十、常见目录结构

1
2
3
4
5
6
7
blog/
├── source/ # 博客源文件
├── themes/ # 主题目录
├── public/ # 生成后的静态文件
├── scaffolds/ # 文章模板
├── _config.yml # Hexo 配置文件
└── package.json

十一、常见问题

1. 修改配置后没生效

执行:

1
hexo clean

然后重新生成。


2. 端口被占用

指定其它端口:

1
hexo s -p 5000

3. 部署失败

检查:

  • Git 是否安装
  • SSH Key 是否配置
  • GitHub Token 是否有效
  • deploy 配置是否正确

十二、推荐插件

搜索插件

1
npm install hexo-generator-searchdb

RSS 订阅

1
npm install hexo-generator-feed

sitemap

1
npm install hexo-generator-sitemap

压缩 HTML/CSS/JS

1
npm install hexo-neat --save

十三、常用快捷命令速查表

功能 命令
创建文章 hexo new "标题"
创建页面 hexo new page "about"
启动服务 hexo s
生成静态文件 hexo g
部署网站 hexo d
清理缓存 hexo clean
生成并部署 hexo g -d
清理+部署 hexo clean && hexo g && hexo d

评论
分享