写好文件,提交到GitHub
将会自动部署Hexo 博客
仓库目录中增加以下文件: .github\workflows\autodeploy.yml
内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| name: 自动部署
on: push: branches: - main
release: types: - published
jobs: deploy: runs-on: ubuntu-latest steps: - name: 检查分支 uses: actions/checkout@v2 with: ref: main
- name: 安装 Node uses: actions/setup-node@v1 with: node-version: "14.x"
- name: 安装 Hexo run: | export TZ='Asia/Shanghai' npm install hexo-cli -g
- name: 缓存 Hexo uses: actions/cache@v1 id: cache with: path: node_modules key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}
- name: 安装依赖 run: | npm -v npm install --save echo "'use strict';const pagination=require('hexo-pagination');module.exports=function(locals){var config=this.config;var posts=locals.posts;posts.data=posts.data.sort(function(a,b){if(a.top==undefined){a.top=0;}if(b.top==undefined){b.top=0;}if(a.top==b.top){return b.date-a.date;}else{return b.top-a.top;}});var paginationDir=config.pagination_dir||'page';return pagination('',posts,{perPage:config.index_generator.per_page,layout:['index','archive'],format:paginationDir+'/%d/',data:{__index:true}});};" > ./node_modules/hexo-generator-index/lib/generator.js
- name: 生成静态文件 run: | hexo clean hexo generate
- name: 部署 run: | cd ./public git init git config --global user.name '${{ secrets.GITHUBUSERNAME }}' git config --global user.email '${{ secrets.GITHUBEMAIL }}' git add . git commit -m "${{ github.event.head_commit.message }} $(date +"%Z %Y-%m-%d %A %H:%M:%S") Updated By Github Actions" git push --force --quiet "https://${{ secrets.GITHUBUSERNAME }}:${{ secrets.GITHUBTOKEN }}@github.com/${{ secrets.GITHUBUSERNAME }}/${{ secrets.GITHUBREPO }}.git" master:main
|
代码中有相应的变量$,需要自行添加到仓库的配置中。