关于一个小白github建blog的故事
前置环境配置
-
cmder(可选)
- https://cmder.net/
Cmder.exe /REGISTER ALL
-
nodejs环境
- nvm(可选)
node -v
- 改源(可选)
-
hexo
-
github
- 账号注册
- 创建私有仓库
- 创建公有仓库
-
配置git
1 | git config --global user.email "you@example.com" |
安装hexo
-
安装hexo
npm install -g hexo-cli
-
安装主题
npm i hexo-theme-butterfly
-
本地运行
hexo clean
hexo g
hexo s
- 访问 http://localhost:4000/
上线github
配置ssh密钥
-
参考文档 :
https://docs.github.com/cn/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
-
使用cmder/gitbash创建密钥
ssh-keygen -t ed25519 -C "your_email@example.com"
-
绑定github 公钥:
https://github.com/settings/keys
-
验证是否成功
ssh -T git@github.com
-
创建公有仓库
传源码
- 配置hexo config.yml
1 | deploy: |
执行 hexo d
cdn优化
-
我们发现当博客在github上时,我们需要很多方法去优化他,不然会非常非常的慢,因为github在国外
-
可以使用又拍云/百度云/自选cf/奇安信等等,注:国内cdn需备案
自动化CICD
- 每次发布博客都需要hexo clean && hexo g && hexo d
- 还需要搭建nodejs环境,那么我们是否可以让他自动化完成这些呢
使用github action
- 我们首先需要建立一个私有仓库
- 在这个私有仓库中我们需要把源码同步上去。
- 之后只需要在这个仓库中把源码拉下来,新增md文档,再次提交就可以直接更新文章了
新建私人仓库
- 略
源码上传
- git clone仓库,直接扔源码
1 | git add . |
- 新建 .github/workflows/main.yml
- 注意其中几个变量需要添加secrets.HEXO_TOKEN /secrets.GIT_NAME/secrets.GIT_EMAIL 需要在项目中添加
- 例子为token添加,还有用密钥添加的都有
1 |
|
seo优化
Search Engine Optimization(搜索引擎优化)
sitemap
1 | npm install hexo-generator-sitemap --save |
站长平台
- 百度站长平台
- Google站长平台
优化url
- hexo-abbrlink
npm install hexo-abbrlink --save
添加robots
1 | User-agent: * |
关于gulp
- 如果使用cdn,大部分cdn自带gulp压缩,所以没必要去进行npm安装gulp
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 impdx!