Last active
January 1, 2024 12:03
-
-
Save lamons/c8a0d42339c03e503bf23a396ed0e87c to your computer and use it in GitHub Desktop.
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
# Sample workflow for building and deploying a Hugo site to GitHub Pages | |
name: Build hugo site with compressed Chinese fonts | |
on: | |
# Runs on pushes targeting the default branch | |
push: | |
branches: ["main"] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Default to bash | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
# Build job | |
build: | |
runs-on: ubuntu-latest | |
env: | |
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} | |
steps: | |
- name: Checkout and env setup | |
uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- uses: BSFishy/pip-action@v1 | |
with: | |
packages: | | |
fonttools[woff] | |
bs4 | |
lxml | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: 'latest' | |
extended: true | |
- name: Add deploy key & configur git | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$ACTIONS_DEPLOY_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan github.com >> ~/.ssh/known_hosts | |
git config --global user.name "tianshi" | |
git config --global user.email "lamons.n@gmail.com" | |
- name: Setup public worktree | |
run: | | |
git worktree add public origin/public | |
cd ./public && git checkout public && git status && cd .. | |
- name: Build with Hugo | |
env: | |
# For maximum backward compatibility with Hugo modules | |
HUGO_ENVIRONMENT: production | |
HUGO_ENV: production | |
run: | | |
hugo --minify --cleanDestinationDir --destination ../public | |
# run: | | |
# ls | |
# chmod +x extract_glyphs.sh | |
# bash extract_glyphs.sh . md,html charset.txt | |
# ls | |
- name: count glyphs | |
run: | | |
cd ../public | |
python ../blog_hugo/extract_glyphs.py | |
- name: Compress font | |
run: | | |
cd ../public/font | |
pyftsubset tenmincho-regular.ttf --text-file="/home/runner/work/blog_hugo/public/other_content.txt" | |
pyftsubset AdvocateAncientSans-VF.ttf --text-file="/home/runner/work/blog_hugo/public/sans_content.txt" | |
for f in *.ttf; do [[ "$f" != *.subset.ttf ]] && rm "$f"; done | |
for f in *.subset.ttf; do mv "$f" "${f%.subset.ttf}.ttf"; done | |
for f in *.ttf; do fonttools ttLib.woff2 compress -o "${f%.*}.woff2" "$f"; done | |
ls -lh | |
cd .. | |
rm *_content.txt | |
cd .. | |
- name: Commit site update with compressed fonts | |
run: | | |
cd ./public | |
rm -rf ./font/* | |
git status | |
cp -frp ../../public/* . | |
git add . | |
git status | |
git commit -m "site update" --branch | |
git push origin public |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment