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