Skip to content

Commit f781fe8

Browse files
committed
add sitemap generation and automated IndexNow integration
1 parent 866847a commit f781fe8

File tree

3 files changed

+64
-45
lines changed

3 files changed

+64
-45
lines changed

deploy-static

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ [email protected]
1616

1717
# use last modified timestamps from attestation.app
1818
rsync -rptcv --chmod=D755,F644 --delete --fsync --preallocate $remote:/srv/attestation.app/ static-production
19+
rsync -pcv --chmod=D755,F644 --fsync --preallocate static-production/sitemap.xml{,.gz,.br} static-tmp/
1920
rsync -rpcv --chmod=D755,F644 --delete --fsync --preallocate static-tmp/ static-production
2021
for f in static-production/**.*(br|gz); do
2122
touch -r "${f%.*}" "$f"
2223
done
24+
changed="$(./generate-sitemap)"
25+
xmllint --noblanks static-tmp/sitemap.xml --output static-tmp/sitemap.xml
26+
brotli -f static-tmp/sitemap.xml
27+
zopfli static-tmp/sitemap.xml
28+
rsync -pcv --chmod=D755,F644 --fsync --preallocate static-tmp/sitemap.xml{,.gz,.br} static-production/
2329

2430
active=$(ssh $remote readlink /srv/attestation.app)
2531

@@ -48,3 +54,7 @@ rsync -pcv --chmod=755 --fsync --preallocate remote-backup $remote:/usr/local/bi
4854
rsync -pcv --chmod=644 --fsync --preallocate systemd/system/remote-backup.timer $remote:/etc/systemd/system/remote-backup.timer
4955
rsync -pcv --chmod=644 --fsync --preallocate systemd/system/remote-backup.service $remote:/etc/systemd/system/remote-backup.service
5056
rsync -pcv --chmod=644 --chown attestation:attestation --fsync --preallocate backup-public-key.txt cloud-archive.sh $remote:/var/lib/attestation/
57+
58+
if [[ -n "$changed" ]]; then
59+
./indexnow <<< "$changed"
60+
fi

generate-sitemap

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
3+
from datetime import datetime, timezone
4+
from os.path import getmtime
5+
from pathlib import Path
6+
7+
base = "https://attestation.app"
8+
9+
pages = [
10+
["/", 1.0],
11+
["/.well-known/security.txt", 0.0],
12+
["/LICENSE.txt", 0.0],
13+
["/about", 1.0],
14+
["/donate", 0.5],
15+
["/contact", 0.1],
16+
["/humans.txt", 0.0],
17+
["/privacy-policy", 0.2],
18+
["/source", 0.1],
19+
["/tutorial", 1.0]
20+
]
21+
22+
base_mtime = getmtime("static-tmp")
23+
entries = []
24+
25+
for page in pages:
26+
path = page[0]
27+
loc = base + path
28+
filepath = "static-production" + path
29+
if path[-1] == '/':
30+
filepath += "index.html"
31+
elif "." not in path:
32+
filepath += ".html"
33+
34+
mtime = getmtime(filepath)
35+
if mtime > base_mtime:
36+
print(loc)
37+
lastmod = datetime.fromtimestamp(mtime, timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%:z")
38+
priority = page[1]
39+
entries.append(f"""
40+
<url>
41+
<loc>{loc}</loc>
42+
<lastmod>{lastmod}</lastmod>
43+
<priority>{priority}</priority>
44+
</url>""")
45+
46+
sitemap = f"""<?xml version="1.0" encoding="UTF-8"?>
47+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
48+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
49+
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">{"".join(entries)}
50+
</urlset>
51+
"""
52+
53+
with open("static-tmp/sitemap.xml", "w") as f:
54+
f.write(sitemap)

static/sitemap.xml

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)