From 94068c3cffa74cf99906e53bb7cef018baa94b19 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 15 May 2024 01:52:10 -0400 Subject: generate sitemap as part of deployment This allows adding the lastmod field based on the last modification date of the file. --- generate-sitemap | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 generate-sitemap (limited to 'generate-sitemap') diff --git a/generate-sitemap b/generate-sitemap new file mode 100755 index 00000000..91cc8408 --- /dev/null +++ b/generate-sitemap @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +from pathlib import Path +from datetime import datetime, timezone +from os.path import getmtime + +base = "https://grapheneos.org" + +pages = [ + ["/", 0.5], + ["/.well-known/security.txt", 0.0], + ["/LICENSE.txt", 0.0], + ["/articles/", 0.5], + ["/articles/attestation-compatibility-guide", 0.5], + ["/articles/grapheneos-servers", 0.1], + ["/articles/server-traffic-shaping", 0.5], + ["/articles/sitewide-advertising-industry-opt-out", 0.5], + ["/build", 0.5], + ["/camera-privacy-policy", 0.0], + ["/contact", 0.5], + ["/donate", 0.5], + ["/faq", 1.0], + ["/features", 1.0], + ["/history/", 0.3], + ["/history/copperheados", 0.1], + ["/history/legacy-changelog", 0.1], + ["/hiring", 0.2], + ["/humans.txt", 0.0], + ["/pdfviewer-privacy-policy", 0.0], + ["/install/", 0.5], + ["/install/cli", 0.5], + ["/install/web", 0.5], + ["/releases", 0.5], + ["/source", 0.5], + ["/usage", 1.0] +] + +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) + 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) -- cgit v1.3.1