hakurei.app/generate-sitemap.py
Ophestra 34b55506fe
All checks were successful
Static / Flake checks (push) Successful in 21s
Static / Create distribution (push) Successful in 40s
static: remove faq page for now
This will be useful after we get some kind of userbase. Omit this for
now since there is nothing to put there.
2025-06-29 03:46:15 +09:00

51 lines
1.3 KiB
Python

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],
["/contact", 0.5],
#["/faq", 1.0],
["/package", 1.0],
["/humans.txt", 0.0],
["/install", 0.5],
]
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"""
<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)