GitHub+Hexo 个人博客搭建:快速建站

软件依赖

  • Node.js (Node.js 版本需不低于 10.13,建议使用 Node.js 12.0 及以上版本)
  • git

创建 Github Page

创建一个名称为 username.github.io 的存储库
https://github.com/new
image-20220112214252824

Hexo

所有必备的应用程序安装完成后,即可使用 npm 安装 Hexo。

Hexo Cli 工具

1
npm install -g hexo-cli

安装 Hexo

初始化项目

1
2
3
hexo init blog
cd blog
npm install

_config.yml

网站的 配置 信息,您可以在此配置大部分的参数
具体查看 https://hexo.io/zh-cn/docs/configuration

Butterfly 主题

https://github.com/jerryc127/hexo-theme-butterfly/blob/dev/README_CN.md

安装主题

  1. 在博客根目录安装主题
    1
    git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
  2. 安装 pug 以及 stylus 的渲染器
    1
    npm install hexo-renderer-pug hexo-renderer-stylus --save
  3. 应用主题
    修改 hexo 配置文件_config.yml,把主题改为 Butterfly
    1
    theme: butterfly

配置主题

  1. 添加配置文件
    1
    cp themes/butterfly/_config.yml _config.butterfly.yml

    本地部署

  2. 生成静态文件并部署
    1
    2
    hexo clean
    hexo g -d
  3. 启动本地服务
    1
    hexo server
    访问 http://localhost:4000/
    image
    image

部署到 Github Pages

  1. 配置 Github SSH
    生成 ssh 密钥文件
    1
    ssh-keygen -t
    然后直接三个回车即可,默认不需要设置密码
    然后找到生成的.ssh 的文件夹中的 id_rsa.pub 密钥,将生成的内容复制

image-20220112214432005

  1. 安装一键部署工具

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

    1
    2
    3
    4
    deploy:
    type: 'git'
    repo: git@github.com:likfees/likfees.github.io.git
    branch: gh-page
  3. 部署

    1
    hexo g -d