将Hexo部署到GitHub

参考Hexo文档

一、安装Git

  1. gitforwindows 下载安装

  2. 安装完查看git版本:

    1
    git --version

二、安装Node.js

  1. node.js 选择LTS的window版本,下载安装

  2. 安装完查看node.js版本

    1
    2
    node -v
    npm -v
  3. 更改npm镜像源:

    1
    npm config set registry https://registry.npm.taobao.org/
  4. 查看npm镜像源:

    1
    npm get registry https://registry.npm.taobao.org/

三、安装Hexo

  1. 安装Hexo

    1
    npm install -g hexo-cli

四、建站

  1. 初始化博客目录

    安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。

    1
    2
    3
    hexo init <folder>
    cd <folder>
    npm install
  2. 常用命令:

    • 清理缓存: hexo clean
    • 生成静态文件: hexo g/generate
    • 生成静态文件: hexo s/server
    • 组合版:hexo clean && hexo g && hexo s
    • 发布到github:hexo d

    本地访问地址:http://localhost:4000

  3. 修改网站基本配置信息参考配置

五、将hexo部署到GitHub

  1. 生成SSH添加到GitHub

    生成key,可以git部署网站

    1
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    然后需要配置

    1
    2
    git config --global user.email “you@example.com”
    git config --global user.name “Your Name”

    将这个文件拷贝到git的https://github.com/settings/keys
    查看是否配置成功

    1
    ssh -T git@github.com
  2. GitHub创建个人仓库
    新建一个 repository。如果你希望你的站点能通过域名 <你的 GitHub 用户名>.github.io 访问,你的 repository 应该直接命名为 <你的 GitHub 用户名>.github.io

  3. 安装 hexo-deployer-git.:

    1
    npm install hexo-deployer-git --save
  4. 在 _config.yml(如果有已存在的请删除)添加如下配置:

    1
    2
    3
    deploy:  
    type: git
    repo: https://github.com/<username>/<project>
  5. 运行 hexo

    1
    clean && hexo deploy
  6. 查看 username.github.io 上的网页是否部署成功。

六、发布文章

  1. 创建文章

    1
    hexo new post "title"
  2. 然后用编辑器修改好文本,发布

    1
    2
    hexo clean && hexo g && hexo s
    hexo clean && hexo deploy