Hexo 安装

安装 Git

下载 Git,安装。

官网下载: https://git-scm.com/
镜像下载: https://npm.taobao.org/mirrors/git-for-windows/

安装完成后,在开始菜单打开 Git Bash,配置用户名称和邮件地址:

1
2
git config --global user.name "John Doe"
git config --global user.email [email protected]

安装 Node.js

https://nodejs.org/zh-cn/ 下载 Node.js,安装。

安装 Hexo

打开 Windows 系统自带的命令提示符,执行以下命令安装 Hexo。<folder> 替换为文件夹名,例如: npm init blog

1
2
3
4
5
npm install -g hexo-cli
hexo init <folder>
cd <folder>
npm install
hexo server

用浏览器访问网址 http://localhost:4000/ 查看效果。

发布到 GitHub

  1. 创建存储库。登录 GitHub 账号(如果没有请到 https://github.com/ 进行注册),创建一个名为 username.github.io 的新存储库,其中 username 是 GitHub 用户名。

  2. 修改配置文件 _config.yml

    1
    2
    3
    4
    deploy:
    type: git
    repo: [email protected]:username/username.github.io.git
    branch: master
  3. 创建 SSH 密钥。在 Git Bash 命令行输入:

    1
    ssh-keygen -t ed25519 -C "[email protected]"

    创建 SSH 密钥。过程中会提示输入要保存密钥的文件(按 Enter 键,默认即可)和输入密码。

  4. 添加 SSH 公钥到 GitHub。输入:

    1
    2
    cd .ssh
    cat id_ed25519.pub

    查看公钥并复制到剪贴板。在 GitHub 的 “Settings” -> “SSH and GPG keys” 新建 SSH 密钥,添加复制的 SSH 密钥。

  5. 接着回到 Git Bash 验证是否添加成功。

    1
    ssh -T [email protected]
  6. 然后再切换到 Windows 命令提示符窗口,安装 hexo-deployer-git。

    1
    npm install hexo-deployer-git --save
  7. 部署到 GitHub。hexo deploy 命令请在 Git Bash 切换路径至相同的目录执行,Windows 命令提示符会因为无法弹出 SSH 密钥验证的窗口而报错。

    1
    2
    3
    hexo clean
    hexo generate
    hexo deploy

    完美结束!!!