Skip to content

Commit 76bd0bc

Browse files
committed
Ping IndexNow crawlers after GitHub Pages deployment
Add a workflow that triggers after the pages-build-deployment completes successfully, fetches the live sitemap, and submits all page URLs to IndexNow (Bing, Yandex, Naver, Seznam, Yep). Google deprecated their ping endpoint in 2023 and offers no CI-callable alternative.
1 parent f6ab2ac commit 76bd0bc

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Ping IndexNow
2+
on:
3+
workflow_run:
4+
workflows: ["pages-build-deployment"]
5+
types:
6+
- completed
7+
jobs:
8+
ping:
9+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v6
13+
with:
14+
ref: source
15+
- name: Fetch live sitemap and ping IndexNow
16+
run: |
17+
curl -sf -o sitemap.xml https://pybuilder.io/sitemap.xml
18+
$GITHUB_WORKSPACE/ping-indexnow.sh sitemap.xml f70e81d625534adb96e7e8d5bd0b438b

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ include:
3030
- .nojekyll
3131
exclude:
3232
- build.sh
33+
- ping-indexnow.sh
3334
- deploy.key
3435
- deploy.key.enc
3536
twitter:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f70e81d625534adb96e7e8d5bd0b438b

ping-indexnow.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash -eEu
2+
3+
# Ping IndexNow with all URLs from the sitemap.
4+
# IndexNow distributes to Bing, Yandex, Naver, Seznam, and Yep.
5+
# Google does not participate in IndexNow (deprecated their ping endpoint in 2023).
6+
7+
SITEMAP_FILE="${1:?Usage: $0 <sitemap-file> <indexnow-key>}"
8+
INDEXNOW_KEY="${2:?Usage: $0 <sitemap-file> <indexnow-key>}"
9+
SITE_HOST="pybuilder.io"
10+
11+
# Extract URLs from sitemap XML
12+
URLS=$(python3 -c "
13+
import xml.etree.ElementTree as ET
14+
tree = ET.parse('$SITEMAP_FILE')
15+
ns = {'s': 'http://www.sitemaps.org/schemas/sitemap/0.9'}
16+
for loc in tree.findall('.//s:loc', ns):
17+
print(loc.text)
18+
")
19+
20+
if [ -z "$URLS" ]; then
21+
echo "No URLs found in sitemap"
22+
exit 1
23+
fi
24+
25+
URL_COUNT=$(echo "$URLS" | wc -l)
26+
echo "Submitting $URL_COUNT URLs to IndexNow"
27+
28+
# Build JSON URL list
29+
URL_JSON=$(echo "$URLS" | python3 -c "
30+
import sys, json
31+
urls = [line.strip() for line in sys.stdin if line.strip()]
32+
print(json.dumps(urls))
33+
")
34+
35+
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "https://api.indexnow.org/indexnow" \
36+
-H "Content-Type: application/json; charset=utf-8" \
37+
-d "{
38+
\"host\": \"$SITE_HOST\",
39+
\"key\": \"$INDEXNOW_KEY\",
40+
\"keyLocation\": \"https://$SITE_HOST/$INDEXNOW_KEY.txt\",
41+
\"urlList\": $URL_JSON
42+
}")
43+
44+
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
45+
BODY=$(echo "$RESPONSE" | head -n -1)
46+
47+
echo "IndexNow response: HTTP $HTTP_CODE"
48+
if [ -n "$BODY" ]; then
49+
echo "$BODY"
50+
fi
51+
52+
case "$HTTP_CODE" in
53+
200|202) echo "IndexNow submission accepted" ;;
54+
*) echo "IndexNow submission failed"; exit 1 ;;
55+
esac

0 commit comments

Comments
 (0)