hexo教程进阶-Github Pages
上次在博客搭建介绍了hexo的基本安装,再来介绍一下hexo如何部署到Github Pages。
首先要在Github上创建一个新的仓库,并且仓库名称是[Github用户名].github.io(公开仓库)。
安装hexo插件 hexo-deployer-git
1
npm install hexo-deployer-git --save
到hexo目录下的_config.yml文件夹内找到deploy项并修改为
1
2
3
4
5deploy:
type: git
repo: 仓库的url # https://github.com/<name>/<name>.github.io.git
branch: master # 一般为master
ignore_hidden: true # default is true配置一下git全局的name和email
1
2git config –global user.name "your_account_name"
git config –global user.email "youremail@example.com"不过这样设置
hexo d
时经常要输密码,可以改为ssh提交方式,不过要一些前置步骤。ssh-keygen -t rsa -C "youremail@example.com"
将email改成github的邮箱。在
~/.ssh
目录下找到id_rsa.pub,打开nano id_rsa.pub
复制全部内容。点击进入https://github.com/settings/keys
点击后将内容粘贴进去。
此时deploy可改为:
1
2
3
4
5deploy:
type: git
repo: git@github.com:<name>/<name>.github.io.git
branch: master
ignore_hidden: true
保存后退出,执行hexo d
,执行完成后可以在仓库内查看到静态网站文件。
进入仓库settings
填写已申请好的域名,最好能勾选一下强制https Enforce HTTPS
,若是没有申请域名,可以直接访问https://<name>.github.io进入网站。
填写好域名后,将域名ALIAS解析到
<name>.github.io
。然后就可以通过自己的域名访问网站了。