Skip to content

Instantly share code, notes, and snippets.

@akkuman
Last active August 20, 2021 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akkuman/5cfc58bf57fe5a3b424cf536e76b0d01 to your computer and use it in GitHub Desktop.
Save akkuman/5cfc58bf57fe5a3b424cf536e76b0d01 to your computer and use it in GitHub Desktop.
我的github pages action
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Build Akkuman Github Pages
on:
push:
branches:
- hugo
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: true
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.87.0'
- name: Build
run: hugo --minify
- name: Set JSDELIVR_CDN
run: echo "JSDELIVR_CDN=https://cdn.jsdelivr.net/gh/$GITHUB_REPOSITORY@master" >> $GITHUB_ENV
- name: WithGit
run: |
# 拉取主仓库
git clone https://github.com/$GITHUB_REPOSITORY.git .deploy_git
# 将先前生成的html丢入仓库
cp -R ./public/* .deploy_git/
cd .deploy_git
# 替换所有html中的本仓库静态文件链接为jsdelivr的cdn
# 并且将主题生成的搜索文件 json 替换为cdn
# 将所有的github图床图片替换为fastgit
find -type f -print0 -name "*.html" | xargs -0 sed -i \
-e '/<head>/,/<\/head>/ s|href=/assets/|href='$JSDELIVR_CDN'/assets/|g' \
-e '/<head>/,/<\/head>/ s|href=../index.json|href='$JSDELIVR_CDN'/index.json|g' \
-e '/<p>/,/<\/p>/ s|<img loading=lazy src=https://raw.githubusercontent.com/|<img loading=lazy src=https://raw.githubusercontents.com/|g'
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/hugo' }}
with:
github_token: ${{ secrets.DEPLOY_PAGES_TOKEN }}
publish_dir: ./.deploy_git
publish_branch: master
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: "14.x"
- name: Push to cnblogs
env:
CNBLOGS_APPKEY: Akkuman
CNBLOGS_USERNAME: Akkuman
CNBLOGS_PASSWORD: ${{ secrets.CNBLOGS_PWD }}
HOME_DIR: .
run: |
echo "ready to pulish to cnblogs"
npm install metaweblog-api markdown-yaml-metadata-parser
node publish_to_cnblogs.js $CNBLOGS_APPKEY $CNBLOGS_USERNAME $CNBLOGS_PASSWORD $HOME_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment