2020 environment :
2121 name : github-pages
2222 runs-on : ubuntu-latest
23- env :
24- INDEXNOW_KEY : ${{ secrets['INDEXNOW_KEY'] }}
2523 steps :
2624 - name : Checkout
2725 uses : actions/checkout@v4
@@ -37,21 +35,16 @@ jobs:
3735 - name : Build docs
3836 run : docfx docs/docfx.json
3937
40- - name : Normalize IndexNow key
41- if : ${{ env.INDEXNOW_KEY != '' }}
42- run : |
43- normalized_key="$(printf '%s' "$INDEXNOW_KEY" | tr -d '\r\n[:space:]')"
44- printf 'INDEXNOW_KEY=%s\n' "$normalized_key" >> "$GITHUB_ENV"
45-
4638 - name : Add IndexNow key file
47- if : ${{ env.INDEXNOW_KEY != '' }}
4839 run : |
49- printf "%s" "$INDEXNOW_KEY" > "docs/_site/${ INDEXNOW_KEY}.txt "
40+ key="${{ secrets. INDEXNOW_KEY }} "
5041
51- - name : Log IndexNow key URL
52- if : ${{ env.INDEXNOW_KEY != '' }}
53- run : |
54- printf 'IndexNow key URL: https://aalmada.github.io/BookStore/%s.txt\n' "$INDEXNOW_KEY"
42+ if [ -z "$key" ]; then
43+ echo "INDEXNOW_KEY secret is not set; skipping IndexNow key file generation."
44+ exit 0
45+ fi
46+
47+ printf '%s\n' "$key" > "docs/_site/${key}.txt"
5548
5649 - name : Fix README images
5750 run : |
@@ -69,67 +62,21 @@ jobs:
6962 url : ${{ steps.deployment.outputs.page_url }}
7063 runs-on : ubuntu-latest
7164 needs : build
72- env :
73- INDEXNOW_KEY : ${{ secrets['INDEXNOW_KEY'] }}
7465 steps :
7566 - name : Deploy to GitHub Pages
7667 id : deployment
7768 uses : actions/deploy-pages@v4
7869
79- - name : Normalize IndexNow key
80- if : ${{ env.INDEXNOW_KEY != '' }}
81- run : |
82- normalized_key="$(printf '%s' "$INDEXNOW_KEY" | tr -d '\r\n[:space:]')"
83- printf 'INDEXNOW_KEY=%s\n' "$normalized_key" >> "$GITHUB_ENV"
84-
8570 - name : Submit IndexNow URLs
86- if : ${{ env.INDEXNOW_KEY != '' }}
8771 run : |
88- key="$INDEXNOW_KEY"
89- site="https://aalmada.github.io/BookStore"
90- key_location="${site}/${key}.txt"
91- summary_file="$GITHUB_STEP_SUMMARY"
72+ key="${{ secrets.INDEXNOW_KEY }}"
9273
93- printf '## IndexNow\n' >> "$summary_file"
94- printf -- '- Site: `%s`\n' "$site" >> "$summary_file"
95- printf -- '- Key file: `%s`\n' "$key_location" >> "$summary_file"
96-
97- key_body="$(curl -fsSL "$key_location")"
98- if [[ "$key_body" != "$key" ]]; then
99- printf 'Key file content mismatch. Expected `%s`, got `%s`.\n' "$key" "$key_body"
100- printf -- '- Submission status: skipped\n' >> "$summary_file"
101- printf -- '- Reason: key file content mismatch.\n' >> "$summary_file"
74+ if [ -z "$key" ]; then
75+ echo "INDEXNOW_KEY secret is not set; skipping IndexNow notification."
10276 exit 0
10377 fi
10478
105- submit_url() {
106- local target_url="$1"
107- local label="$2"
108- local response_file
109- response_file="$(mktemp)"
110-
111- local status
112- status="$(curl -sS -o "$response_file" -w '%{http_code}' --get \
113- --data-urlencode "url=${target_url}" \
114- --data-urlencode "key=${key}" \
115- --data-urlencode "keyLocation=${key_location}" \
116- "https://api.indexnow.org/indexnow")"
117-
118- printf 'IndexNow %s status: %s\n' "$label" "$status"
119- cat "$response_file"
120-
121- printf -- '- %s status: %s\n' "$label" "$status" >> "$summary_file"
122-
123- local response_body
124- response_body="$(cat "$response_file")"
125- if [[ -n "$response_body" ]]; then
126- printf -- '- %s response: `%s`\n' "$label" "$response_body" >> "$summary_file"
127- fi
128-
129- rm -f "$response_file"
130- }
131-
132- submit_url "${site}/" "homepage"
133- submit_url "${site}/sitemap.xml" "sitemap"
134-
135- printf -- '- Submission status: completed\n' >> "$summary_file"
79+ site="https://aalmada.github.io/BookStore"
80+ key_location="${site}/${key}.txt"
81+ curl -fsS "https://api.indexnow.org/indexnow?url=${site}/&key=${key}&keyLocation=${key_location}"
82+ curl -fsS "https://api.indexnow.org/indexnow?url=${site}/sitemap.xml&key=${key}&keyLocation=${key_location}"
0 commit comments