基础指令

1. 初始化博客项目

1
hexo init <folder>  # 在指定文件夹初始化Hexo项目

2. 新建文章

1
2
hexo new "文章标题"       # 在 source/_posts 下生成新文章
hexo new draft "草稿标题" # 在 source/_drafts 下生成草稿

3. 生成静态文件

1
hexo generate  # 或简写为 hexo g

4. 启动本地服务器

1
2
3
4
hexo server    # 或简写为 hexo s
# 常用参数:
hexo s -p 4000 # 指定端口
hexo s -o # 启动后自动打开浏览器

5. 部署到远程仓库

1
2
hexo deploy    # 或简写为 hexo d
# 需要提前配置 _config.yml 的 deploy 字段(如Git仓库)

6. 清除缓存和生成文件

1
hexo clean     # 删除缓存和 public 文件夹(解决页面未更新问题)

组合指令

1. 生成并生成本地预览

1
hexo g -s  # 等同于 hexo generate && hexo server

2. 生成并部署

1
hexo d -g  # 等同于 hexo generate && hexo deploy

其他指令

1. 新建页面

1
hexo new page "about"  # 生成 source/about/index.md

2. 发布草稿为正式文章

1
hexo publish "草稿标题"  # 将 _drafts 中的草稿移动到 _posts

3. 列出所有文章

1
hexo list post  # 显示所有文章信息

4. 自定义配置文件

1
hexo g --config custom.yml  # 使用指定配置文件生成

5. 显示版本

1
hexo version

[!NOTE]

  • 部署依赖插件:使用hexo deploy前需要安装部署插件(如部署到Git需安装 hexo-deployer-git):
1
npm install hexo-deployer-git --save
  • 实时更新:修改 _config.yml 后需重启服务器或重新生成文件。
  • 草稿预览:本地启动时添加 --draft 参数可预览草稿
1
hexo s --draft