hexo部署github
GitHub设置
已经有了账号,本地也有sshkey,所以需要把id_rsa.pub文件的内容复制到账号–setting–”SSH and GPG keys”下面
验证是否成功的方式:
ssh -T git@github.com
进入github.com的网站,选择Repositories旁边的 New,输入
uuair.github.io
作为Repository name,下面选择 Add a README file,最后选 Create repository进入后选择 Settings,注意在General中Default branch这里写的是什么,我的是main
选择Pages后,Source这里选择Deploy from a branch, Branch 这里选择main
同时上面的GitHub Pages这里会显示访问的地址:
https://uuair.github.io
本地设置
- 下载nodejs
- 安装hexo:
npm install hexo-cli -g
- 设置好本地目录:比如我的blog
1
2
3
4hexo init blog
cd blog
npm install
npm install hexo-deployer-git --save- hexo命令:
1
2
3
4
5hexo clean // 清空
hexo g // g=generate 生成静态目录
hexo d // d=deploy 发布
hexo s // s=server 本地调试,浏览器localhost:4000
hexo new test //发一篇文章 - 网站设置在文件 _config.yml中,下面是配置说明:
- title :网站标题
- subtitle: 副标题
- description: 网站描述
- author: 作者名字
- language: zn-CN 网站语言
每一个冒号后面跟一个英文的空格
- 配置主题:
git clone https://github.com/cjquines/hexo-theme-ascent themes/ascent
- 修改 _config.yml的 Deployment部分:
1
2
3
4
5
6# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: 'git'
repo: git@github.com:uuair/uuair.github.io.git
branch: main
- repo的部分在github的 Code下面的 SSH中复制
- branch必须跟settings中 GitHub Pages 指定的Branch一样
- 修改 themes 部分:
theme: ascent
- 文章发布在 source/_posts中存为md格式
- source 目录下新建CNAME 文件,里面写上绑定的二级域名
it.leon.vc
,然后在settings–Pages 下的Custom domain中验证域名,这样可以绑定域名.