核心组件拆解
1. 基础Workflow配置
2. 关键检测维度实现
实战技巧
自定义规则引擎
智能报告生成
避坑指南
进阶方案
每次手动检查SEO问题就像用牙签搭埃菲尔铁塔——耗时费力还容易漏掉关键细节。对于日更技术博客的全栈开发者来说,自动化的SEO检测能节省60%的维护时间。Google Search Console数据显示,自动检测SEO问题的博客在3个月内自然流量平均提升47%。
核心组件拆解
1. 基础Workflow配置
| name: SEO Audit |
| on: |
| schedule: |
| - cron: '0 12 * * 1-5' |
| push: |
| branches: [ main ] |
| |
| jobs: |
| seo-check: |
| runs-on: ubuntu-latest |
| steps: |
| - uses: actions/checkout@v3 |
| - name: Setup Node |
| uses: actions/setup-node@v3 |
| with: |
| node-version: '16' |
2. 关键检测维度实现
| const { BrokenLinkChecker } = require('broken-link-checker'); |
| const blc = new BrokenLinkChecker({ |
| excludeExternalLinks: true, |
| filterLevel: 1 |
| }); |
| const $ = cheerio.load(html); |
| const metaDesc = $('meta[name="description"]').attr('content'); |
| if (!metaDesc || metaDesc.length < 120) { |
| core.setFailed('描述标签过短'); |
| } |
| const hTags = {}; |
| $(':header').each((i, el) => { |
| const tagName = el.name.toLowerCase(); |
| hTags[tagName] = (hTags[tagName] || 0) + 1; |
| }); |
| if (!hTags.h1 || hTags.h1 > 1) { |
| core.setFailed('H1标签缺失或重复'); |
| } |
实战技巧
自定义规则引擎
创建.seorules.json
配置文件:
| { |
| "img_alt": { |
| "threshold": 0.95, |
| "message": "图片ALT属性覆盖率不足" |
| }, |
| "canonical": { |
| "required": true, |
| "message": "缺少canonical标签" |
| } |
| } |
智能报告生成
集成Lighthouse CI生成可视化报告:
| - name: Run Lighthouse |
| run: | |
| npm install -g @lhci/cli |
| lhci autorun --upload.target=temporary-public-storage |
| |
避坑指南
- 频率控制:避免触发GitHub Actions的速率限制(每小时100次API调用)
- 敏感信息:使用
actions/github-script
时务必配置GITHUB_TOKEN
权限
- 性能优化:对于大型博客,使用
strategy.matrix
进行分片检测
进阶方案
- 结合Google Analytics API获取真实流量数据
- 集成Slack/webhook实现即时告警
- 使用Headless Chrome进行渲染层SEO检查
案例:某Vue技术博客实施后,404错误减少82%,搜索点击率提升35%。关键在于持续迭代检测规则——就像写单元测试一样对待SEO。