创建仓库
- 访问:https://github.com/new
- 创建仓库,名称写
xxx.github.io
。
环境配置
1. 下载安装 Git 环境
设置 GitHub SSH Key。
2. 搭建 Node.js 环境
推荐使用 nvm:文章链接。
Hexo 的使用
1. 安装 Hexo
1 | npm install -g hexo-cli |
如果进度条长时间没有变化,切换到淘宝 NPM 镜像:
1 | npm config set registry https://registry.npmmirror.com |
2. 初始化 Hexo 框架
1 | hexo init blog |
3. 安装相关依赖
1 | npm install |
4. 启动本地服务
1 | hexo server |
浏览器访问:localhost:4000。
配置 Next 主题
进入上一步创建的
blog
文件夹,将 Next 主题相关文件从 GitHub 克隆到themes
文件夹中:1
git clone https://github.com/iissnan/hexo-theme-next themes/next
配置 Hexo 的主题参数:
- 修改根目录的
_config.yml
文件中的theme
参数为:1
theme: next
- 修改根目录的
启动 Hexo 服务,验证 Next 主题是否启用。
浏览器访问 localhost:4000 时出错
错误内容
浏览器显示内容如下所示:
1 | {% extends '_layout.swig' %} {% import '_macro/post.swig' as post_template %} {% import '_macro/sidebar.swig' as |
解决方案
这是因为 Hexo 在 5.0 之后删除了 swig
,需要自己手动安装:
1 | npm i hexo-renderer-swig |
添加博客内容
- 将写好的 Markdown 放到
source/_posts
目录。 - 将相应的图片放到
source/images
目录。 - 启动 Hexo 服务(如果之前没有关闭,请忽略此步骤)。
- 通过浏览器访问博客主页,可以发现更改已生效。
将生成的静态页面部署到 GitHub 上
1. 安装 deploy-git
1 | npm install hexo-deployer-git --save |
2. 修改站点配置文件 _config.yml
的最后部分:
1 | deploy: |
3. 部署博客
1 | hexo clean # 清除之前生成的内容 |
4. 设置GitHub Pages
在 GitHub 仓库Settings Pages Source 为 Deploy from a branch ,Branch选择pages分支,点击保存save
现在,你可以在 http://xxx.github.io 看到你的博客了!