#GitHub Actions #自动化 #SEO #CI/CD
静态网站最大的敌人是「死掉」:内容不更新,搜索引擎爬虫来的次数越来越少, 访客看到三个月前的时间戳也会失去信任。解决方案是让内容自己保持新鲜—— 用 GitHub Actions 定时任务自动维护。
一个文件搞定,放在 .github/workflows/freshness.yml:
name: Weekly content freshness
on:
schedule:
- cron: "0 3 * * 1" # 每周一 03:00 UTC
workflow_dispatch:
permissions:
contents: write
jobs:
update-timestamp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
- name: Update last-updated marker
run: |
echo "Updated: $(date -u +'%Y-%m-%d %H:%M UTC')" > docs/.last-updated
git config user.name "xuanjing-bot"
git config user.email "bot@toolgen.xyz"
git add docs/.last-updated
if git diff --cached --quiet; then
echo "no changes"
else
git commit -m "chore: weekly freshness update [skip ci]"
git push
fi
- name: Ping Bing IndexNow
run: |
curl -s -m 30 -X POST "https://www.bing.com/indexnow" -H "Content-Type: application/json" -d '{"host":"toolgen.xyz","key":"YOUR_KEY","keyLocation":"https://toolgen.xyz/ix-key.txt","urlList":["https://toolgen.xyz/"]}'
echo ""
用 API 手动触发 workflow 验证:POST /repos/{owner}/{repo}/actions/workflows/{file}/dispatches,
然后轮询 runs 接口看状态。我们实测从 queued 到 completed success 大约 30 秒。
如果失败,去 Actions 页面看日志——最常见的坑是 git push 需要配置 user.name/user.email。
这套机制上线后:网站每周自动更新一次,Bing 收录从「待爬取」变成「已受理」, Google 也开始出现 site 搜索痕迹。自动化维护的意义不是省那几分钟, 而是让搜索引擎和访客都看到「这个站是活的」。