环境需求

  1. 安装 NodeJS
  2. 安装 Git
  3. 更换为淘宝的NPM镜像
1
npm config set registry https://registry.npmmirror.com/
  1. 安装Hexo
1
npm install -g hexo-cli

初始化Blog

在一个新文件夹内,运行

1
2
hexo init
npm install

然后执行

1
hexo s

常用命令

1
2
3
4
hexo clean   # 清空缓存
hexo generate # 生成静态文件(简写 hexo g)
hexo server # 本地预览(简写 hexo s)
hexo deploy # 部署到服务器(需配置)

一键部署 GitHub Pages

  1. 注册

注册 GitHub 账号,新建仓库
仓库名:用户名.github.io

  1. 配置Git信息
1
2
git config --global user.name "你的GitHub用户名"
git config --global user.email "你的GitHub邮箱"
  1. 安装插件

在hexo博客文件夹下,执行npm install hexo-deployer-git --save安装插件

  1. 配置

打开博客根目录 _config.yml,拉到最底部,替换部署配置

1
2
3
4
deploy:
type: git
repo: https://github.com/你的用户名/你的用户名.github.io.git #或者你的git://.....
branch: main
  1. 发布相关命令
1
2
3
hexo clean    # 清缓存
hexo g # 生成静态页面
hexo d # 自动推送部署