Skip to content

Commit 4b95636

Browse files
TowyTowyclaude
andcommitted
feat: submit changed pages to IndexNow after deploy
Pings api.indexnow.org with the URLs of markdown pages changed in each push to main, so Bing-family engines (Bing/Copilot/ChatGPT search, Yandex) recrawl updated pages quickly. Google ignores IndexNow. The key file in docs/public/ is served at the site root for verification. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 11a6e39 commit 4b95636

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,56 @@ jobs:
7171
- name: Deploy to GitHub Pages
7272
id: deployment
7373
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4c037b783fbf7d87c71f574bef22136f

0 commit comments

Comments
 (0)