Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ping-indexnow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Ping IndexNow
on:
workflow_run:
workflows: ["pages-build-deployment"]
types:
- completed
jobs:
ping:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: source
- name: Fetch live sitemap and ping IndexNow
run: |
curl -sf -o sitemap.xml https://pybuilder.io/sitemap.xml
$GITHUB_WORKSPACE/ping-indexnow.sh sitemap.xml f70e81d625534adb96e7e8d5bd0b438b
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ include:
- .nojekyll
exclude:
- build.sh
- ping-indexnow.sh
- deploy.key
- deploy.key.enc
twitter:
Expand Down
1 change: 1 addition & 0 deletions f70e81d625534adb96e7e8d5bd0b438b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f70e81d625534adb96e7e8d5bd0b438b
55 changes: 55 additions & 0 deletions ping-indexnow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash -eEu

# Ping IndexNow with all URLs from the sitemap.
# IndexNow distributes to Bing, Yandex, Naver, Seznam, and Yep.
# Google does not participate in IndexNow (deprecated their ping endpoint in 2023).

SITEMAP_FILE="${1:?Usage: $0 <sitemap-file> <indexnow-key>}"
INDEXNOW_KEY="${2:?Usage: $0 <sitemap-file> <indexnow-key>}"
SITE_HOST="pybuilder.io"

# Extract URLs from sitemap XML
URLS=$(python3 -c "
import xml.etree.ElementTree as ET
tree = ET.parse('$SITEMAP_FILE')
ns = {'s': 'http://www.sitemaps.org/schemas/sitemap/0.9'}
for loc in tree.findall('.//s:loc', ns):
print(loc.text)
")

if [ -z "$URLS" ]; then
echo "No URLs found in sitemap"
exit 1
fi

URL_COUNT=$(echo "$URLS" | wc -l)
echo "Submitting $URL_COUNT URLs to IndexNow"

# Build JSON URL list
URL_JSON=$(echo "$URLS" | python3 -c "
import sys, json
urls = [line.strip() for line in sys.stdin if line.strip()]
print(json.dumps(urls))
")

RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "https://api.indexnow.org/indexnow" \
-H "Content-Type: application/json; charset=utf-8" \
-d "{
\"host\": \"$SITE_HOST\",
\"key\": \"$INDEXNOW_KEY\",
\"keyLocation\": \"https://$SITE_HOST/$INDEXNOW_KEY.txt\",
\"urlList\": $URL_JSON
}")

HTTP_CODE=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | head -n -1)

echo "IndexNow response: HTTP $HTTP_CODE"
if [ -n "$BODY" ]; then
echo "$BODY"
fi

case "$HTTP_CODE" in
200|202) echo "IndexNow submission accepted" ;;
*) echo "IndexNow submission failed"; exit 1 ;;
esac