from datetime import datetime, timezone
from os.path import getmtime
from pathlib import Path
base = "https://hakurei.app"
pages = [
["/", 0.5],
["/LICENSE.txt", 0.0],
["/build", 0.5],
["/camera-privacy-policy", 0.0],
["/contact", 0.5],
["/faq", 1.0],
["/package", 1.0],
["/hiring", 0.2],
["/humans.txt", 0.0],
["/pdfviewer-privacy-policy", 0.0],
["/install/", 0.5],
["/install/cli", 0.5],
["/install/web", 0.5],
["/usage", 1.0]
]
base_mtime = getmtime("static-tmp")
entries = []
for page in pages:
path = page[0]
if path[-1] != '/' and "." not in path:
path += ".html"
loc = base + path
filepath = "static-production" + path
if path[-1] == '/':
filepath += "index.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"""
{loc}
{lastmod}
{priority}
""")
sitemap = f"""
{"".join(entries)}
"""
with open("static-tmp/sitemap.xml", "w") as f:
f.write(sitemap)