修复 MoeICP #343
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto build blog | |
on: | |
push: | |
branches: | |
- main | |
repository_dispatch: | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
deployments: write | |
strategy: | |
fail-fast: false | |
matrix: | |
platform: | |
- main | |
- cn | |
steps: | |
- name: Set up Node.js | |
uses: actions/setup-node@main | |
with: | |
node-version: 16.x | |
- uses: actions/setup-python@main | |
with: | |
python-version: 3.x | |
- name: Check out code | |
uses: actions/checkout@main | |
- name: Fetch Posts | |
run: | | |
git clone https://${{secrets.POST_CHECKOUT_TOKEN}}@github.com/Potat0000/Blog-Posts.git source/_posts | |
python3 build_script/gen_updatedtime.py | |
rm -rf source/_posts/.git* | |
- name: Install packages | |
run: | | |
npm install -g hexo-cli | |
npm install | |
- name: Get and Patch Lib Files | |
run: | | |
echo "MOEICP=20221816" >> $GITHUB_ENV | |
echo "OSS_BUCTET=potat0-box" >> $GITHUB_ENV | |
echo "REFRESH_URL=xn--udsw05j.space" >> $GITHUB_ENV | |
mv source/favicon/* source/ | |
rm -rf source/favicon | |
curl https://cdn.jsdelivr.net/gh/PrismJS/prism-themes@master/themes/prism-material-light.min.css --create-dirs -o node_modules/prismjs/themes/prism-materiallight.css | |
curl https://cdn.jsdelivr.net/gh/PrismJS/prism-themes@master/themes/prism-material-oceanic.min.css --create-dirs -o node_modules/prismjs/themes/prism-materialoceanic.css | |
sed -i 's,http://,https://,g' node_modules/hexo-theme-fluid/layout/_partials/footer/beian.ejs | |
- name: Patch for CN-Domain website | |
if: ${{ matrix.platform == 'cn' }} | |
run: | | |
echo "MOEICP=20241816" >> $GITHUB_ENV | |
echo "OSS_BUCTET=potat0-box-cn" >> $GITHUB_ENV | |
echo "REFRESH_URL=potat0.cc" >> $GITHUB_ENV | |
sed -i 's/potat0.cc/土豆.space/g' _config.yml | |
sed -i 's/potat0.cc/土豆.space/g' source/manifest.json | |
sed -i 's/potat0.cc/土豆.space/g' source/robots.txt | |
sed -i 's/icp_text: 浙ICP备2021017952号-1/icp_text: 浙ICP备2021017952号-2/g' _config.fluid.yml | |
sed -i 's/police_text: 浙公网安备33010602011812号/police_text:/g' _config.fluid.yml | |
sed -i 's/police_code: 33010602011812/police_code:/g' _config.fluid.yml | |
- name: Build | |
run: | | |
hexo g | |
sed -i 's,IEJUMPIEJUMPIEJUMP,if(/*@cc_on!@*/false||(!!window.MSInputMethodContext\&\&!!document.documentMode))window.location.href="https://support.dmeng.net/upgrade-your-browser.html?referrer="+encodeURIComponent(window.location.href);,g' $(grep IEJUMPIEJUMPIEJUMP -rl ./public) | |
sed -i -z "s,<div class=\"beian\">.*<span>,<div class=\"beian\"><span><a href=\"https://icp.gov.moe/?keyword=$MOEICP\"target=\"_blank\"rel=\"nofollow\">萌ICP备$MOEICP号</a></span><span style=\"margin-bottom:.25rem\">,g" $(grep '<div class="beian">' -rl ./public) | |
- name: Clean up | |
run: | | |
cd public | |
rm -rf xml | |
rm img/default.png img/fluid.png | |
- name: Minify | |
uses: docker://devatherock/minify-js:3.0.0 | |
with: | |
directory: public | |
add_suffix: false | |
- name: Deploy to Aliyun OSS | |
uses: fangbinwei/aliyun-oss-website-action@v1 | |
with: | |
accessKeyId: ${{ secrets.ALIYUN_ACCESSKEY_ID }} | |
accessKeySecret: ${{ secrets.ALIYUN_ACCESSKEY_SECRET }} | |
bucket: ${{ env.OSS_BUCTET }} | |
endpoint: oss-cn-hangzhou.aliyuncs.com | |
folder: public | |
incremental: true | |
skipSetting: true | |
- name: Refresh Aliyun CDN | |
uses: visionwx/ali-cdn-refresh@v0.1.1 | |
with: | |
accessKeyId: ${{ secrets.ALIYUN_ACCESSKEY_ID }} | |
accessKeySecret: ${{ secrets.ALIYUN_ACCESSKEY_SECRET }} | |
type: Directory | |
path: https://${{ env.REFRESH_URL }}/ |