Skip to content

remove pre/next in markdown #1207

remove pre/next in markdown

remove pre/next in markdown #1207

Workflow file for this run

name: Deploy《LeetCode-Cookbook》
on:
push:
branches:
- master # 只在master上push触发部署
- add_hugo
paths-ignore: # 下列文件的变更不触发部署,可以自行添加
- README.md
- LICENSE
jobs:
deploy:
runs-on: ubuntu-latest # 使用ubuntu系统镜像运行自动化脚本
steps: # 自动化步骤
- uses: actions/checkout@v5 # 第一步,下载代码仓库
with:
fetch-depth: 0 # config.toml 里 enableGitInfo = true,需要完整 git 历史,否则取不到每页“最后修改”信息
- name: Setup Hugo # 第二步,安装 hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.74.3'
extended: true # 关键修复:主题用 resources.ToCSS 编译 book.scss,必须用 extended 版,否则 build 直接报错
- name: Build # 第三步,编译 hugo
run: |
cd ./website
hugo -D --minify
- name: Deploy to Server # 第四步:在 runner 上用 rsync 把构建产物推到服务器
# 关键修复:之前用 appleboy/ssh-action,它会把 script 放到“服务器上”执行,
# 于是 rsync 在服务器本机找不到 ./website/public/,还要再 SSH 回自己 → Permission denied。
# 正确做法是直接在 runner 上跑 rsync,用 DEPLOY_KEY 推到服务器。
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SERVER_PORT: ${{ secrets.SERVER_PORT }}
SERVER_DESTINATION: ${{ secrets.SERVER_DESTINATION }}
run: |
mkdir -p ~/.ssh
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
# 服务器较旧(OpenSSH 5.x),只认旧的 ssh-rsa(SHA-1) 签名,
# 而新版 OpenSSH 默认禁用了它,所以要显式加回 PubkeyAcceptedAlgorithms=+ssh-rsa,
# 否则会报 "sign_and_send_pubkey: no mutual signature supported"。
rsync -avz --delete --exclude='*.pyc' \
-e "ssh -i ~/.ssh/deploy_key -p ${SERVER_PORT:-22} -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o PubkeyAcceptedAlgorithms=+ssh-rsa" \
./website/public/ \
"${SSH_USERNAME}@${SSH_HOST}:${SERVER_DESTINATION:-/var/www/books/leetcode/}"
word-count: # 重新统计总字数,并通过 PR 刷新 README 里的徽章数字
# 只在 master 上跑(add_hugo 等分支不自动改 README)。
# master 是受保护分支(必须走 PR),所以这里不直接 push,而是开/更新一个 PR。
# 需要在 Settings → Actions → General → Workflow permissions 勾选
# "Allow GitHub Actions to create and approve pull requests"。
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: write # 推送 PR 分支
pull-requests: write # 创建/更新 PR
steps:
- uses: actions/checkout@v5
- name: Compute total word count # 跑仓库自带脚本(标准库即可,ubuntu-latest 自带 python3)
id: wc
run: |
COUNT=$(python3 website/content/ChapterFour/pytool/WordCount.py | awk '/total word count/{print $NF}')
# 防御:脚本异常时不要用空值/非数字去覆盖徽章
if ! echo "$COUNT" | grep -qE '^[0-9]+$'; then
echo "WordCount.py 未返回有效数字:'$COUNT'"; exit 1
fi
echo "total word count = $COUNT"
echo "count=$COUNT" >> "$GITHUB_OUTPUT"
- name: Update badge number in README
run: |
sed -i -E "s#(Total%20Word%20Count-)[0-9]+(-success)#\1${{ steps.wc.outputs.count }}\2#" README.md
- name: Open/update PR if the badge changed
# 仅当 README 真的变了才会建/更新 PR;固定分支名 chore/word-count-badge,
# 始终复用同一个 PR,不会刷屏。合并即可更新徽章。
uses: peter-evans/create-pull-request@v6
with:
add-paths: README.md
branch: chore/word-count-badge
delete-branch: true
commit-message: "chore: update Total Word Count badge to ${{ steps.wc.outputs.count }}"
title: "chore: update Total Word Count badge to ${{ steps.wc.outputs.count }}"
body: |
自动刷新 README 的 Total Word Count 徽章为 **${{ steps.wc.outputs.count }}**
(口径:汉字 + 英文单词,已剔除代码块;由 `website/content/ChapterFour/pytool/WordCount.py` 统计)。
合并即可更新徽章;若数字没变化则不会创建本 PR。