|
71 | 71 | - name: Deploy to GitHub Pages |
72 | 72 | id: deployment |
73 | 73 | uses: actions/deploy-pages@v5 |
| 74 | + |
| 75 | + indexnow: |
| 76 | + # Ping IndexNow with the pages changed in this push so Bing-family engines |
| 77 | + # (Bing/Copilot/ChatGPT search, Yandex, etc.) recrawl them quickly. |
| 78 | + # Google does not use IndexNow. The key is public by design; it must match |
| 79 | + # docs/public/<key>.txt served at the site root. |
| 80 | + if: github.event_name == 'push' |
| 81 | + needs: deploy |
| 82 | + runs-on: ubuntu-latest |
| 83 | + steps: |
| 84 | + - name: Checkout repository |
| 85 | + uses: actions/checkout@v6 |
| 86 | + with: |
| 87 | + fetch-depth: 0 |
| 88 | + |
| 89 | + - name: Submit changed URLs to IndexNow |
| 90 | + env: |
| 91 | + INDEXNOW_KEY: 4c037b783fbf7d87c71f574bef22136f |
| 92 | + HOST: airpodsreplicas.com |
| 93 | + run: | |
| 94 | + BEFORE="${{ github.event.before }}" |
| 95 | + # Force pushes and new branches have a null/unknown before SHA; |
| 96 | + # fall back to just the head commit's changes. |
| 97 | + if [ -z "$BEFORE" ] || ! git cat-file -e "$BEFORE" 2>/dev/null; then |
| 98 | + BEFORE="${{ github.sha }}^" |
| 99 | + fi |
| 100 | + # Map changed markdown pages to their cleanUrls form: index.md becomes |
| 101 | + # the directory URL (trailing slash, matching sitemap canonicals), |
| 102 | + # other pages drop the .md extension. Deleted pages are submitted too — |
| 103 | + # IndexNow recrawls them and drops them from the index. |
| 104 | + urls=$(git diff --name-only "$BEFORE" "${{ github.sha }}" -- docs/ \ |
| 105 | + | grep '\.md$' \ |
| 106 | + | grep -v -e '^docs/\.vitepress/' -e '^docs/public/' \ |
| 107 | + | sed -E "s|^docs/||; s|index\.md$||; s|\.md$||; s|^|https://$HOST/|" \ |
| 108 | + | sort -u) |
| 109 | + if [ -z "$urls" ]; then |
| 110 | + echo "No doc pages changed; skipping IndexNow ping." |
| 111 | + exit 0 |
| 112 | + fi |
| 113 | + echo "Submitting $(printf '%s\n' "$urls" | wc -l | tr -d ' ') URL(s) to IndexNow:" |
| 114 | + printf '%s\n' "$urls" |
| 115 | + payload=$(printf '%s\n' "$urls" | jq -R . | jq -s --arg host "$HOST" --arg key "$INDEXNOW_KEY" \ |
| 116 | + '{host: $host, key: $key, keyLocation: "https://\($host)/\($key).txt", urlList: .}') |
| 117 | + status=$(curl -sS -o /tmp/indexnow-response.txt -w '%{http_code}' \ |
| 118 | + -X POST 'https://api.indexnow.org/indexnow' \ |
| 119 | + -H 'Content-Type: application/json; charset=utf-8' \ |
| 120 | + -d "$payload") |
| 121 | + echo "IndexNow response: HTTP $status" |
| 122 | + cat /tmp/indexnow-response.txt || true |
| 123 | + # 200 = OK, 202 = accepted (key validation pending) |
| 124 | + if [ "$status" != "200" ] && [ "$status" != "202" ]; then |
| 125 | + exit 1 |
| 126 | + fi |
0 commit comments