之后就可以直接在私人倉庫source/_posts/里面添加.md文件啦,可以隨時隨地寫文章發(fā)文章
不知所措的新哥
https://xin520.xyz
https://xin520.site
https://xin520.plus
https://anxinweb.github.io
https://xin-lac.vercel.app
GitHub Actions 來自動部署 Hexo:https://zhuanlan.zhihu.com/p/170563000
github將整個文件夾推送到自己的倉庫:https://blog.csdn.net/viafcccy/article/details/85527118
前提
node.js 環(huán)境 和 git 都已正確安裝 (其實能正常運行 hexo 就已經(jīng)說明正確安裝了)
hexo 可以正常運行 可以正常部署(這里介紹部署到 github pages )
配置好hexo的主題,博客名稱等等
ok,有了以上前提,可以繼續(xù)了
_config.yml 文件中在前提情況下,已經(jīng)配置好了:
deploy:
type: git
repo: https://github.com/用戶名/倉庫名.git
branch: master
此時我們需要將上面 repo 的配置改成 ssh 格式——即 git@github.com:用戶名/倉庫名.git
避免在執(zhí)行 actions 時 部署出錯
隨便在任何文件位置可以直接右鍵 git bash here
復(fù)制粘貼這個 ssh-keygen -t rsa -b 4096 -C "Hexo Deploy Key" -f github-deploy-key -N ""
會在當(dāng)前目錄生成兩個文件
Settings -> Secrets
,New secret
EXO_DEPLOY_KEY
注意大小寫,這個后面的 GitHub Actions Workflow 要用到,一定不能寫錯。Settings -> Deploy keys
,Add deploy key
在私人代碼倉庫里點 Actions
然后創(chuàng)建一個新文件 .github/workflows/deploy.yml
deploy 名字可以自取但是一定要放在.github/workflows
目錄中
name: Hexo Deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-18.04
if: github.event.repository.owner.id == github.event.sender.id
steps:
- name: Checkout source
uses: actions/checkout@v2
with:
ref: master
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '12'
- name: Setup Hexo
env:
ACTION_DEPLOY_KEY: ${{ secrets.HEXO_DEPLOY_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_rsa
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
git config --global user.email "改成你的郵箱"
git config --global user.name "改成你的用戶名"
npm install hexo-cli -g
npm install
- name: Deploy
run: |
hexo clean
hexo deploy
ok,這樣就完美搞定 github action 和 GitHub pages 的連接啦,并且可以自動觸發(fā) Workflow 執(zhí)行動作
俺是一個純小白,只能傻瓜式的推送部署到倉庫了
在任意位置 git bash here 然后 輸入 git clone https://github.com/用戶名/倉庫名.git
將私人倉庫給克隆下來
將所有的hexo文件都復(fù)制到剛剛克隆下來的文件夾里面
然后 git init
將該克隆下的文件夾變成Git可以管理的倉庫
git add .
通過git add將所有文件提交到暫存區(qū)
git commit -m 'the initial edition'
版本描述
git remote add origin https://github.com/用戶名/倉庫名.git
與倉庫關(guān)聯(lián)
git pull
第一次推送需要
git push -u origin master
帶有-u這個參數(shù)是指,將master分支的所有內(nèi)容都提交,第一次關(guān)聯(lián)之后后邊你再提交就可以不用這個參數(shù)了
git push origin master
之后你的每一次修改,你就可以只將你修改用這個push就好了
此時,所有的hexo文件全都git到倉庫了,之后就可以直接在私人倉庫source/_posts/里面添加.md文件啦,可以隨時隨地寫文章發(fā)文章,不受設(shè)備和配置環(huán)境干擾啦。
俺是一個純小白,都是一步一步按照別人的步驟踩坑摸索來的,不容易嗚嗚嗚。