summaryrefslogtreecommitdiff
path: root/generate-sitemap
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xgenerate-sitemap40
1 files changed, 40 insertions, 0 deletions
diff --git a/generate-sitemap b/generate-sitemap
new file mode 100755
index 0000000..998b9ec
--- /dev/null
+++ b/generate-sitemap
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+from os import path
+import textwrap
+import sys
+
+from typing import List
+
+import jinja2
+
+ROOT = 'https://ethulhu.co.uk'
+
+TEMPLATE = '''
+<?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'>
+ {% for url in urls -%}
+ <url>
+ <loc>{{ root }}/{{ url.loc }}</loc>
+ </url>
+ {% endfor %}
+</urlset>
+'''.strip()
+
+
+def loc_from_path(p: str) -> str:
+ basename, _ = path.splitext(p)
+ return '/'.join(basename.split('/')[1:])
+
+
+if __name__ == '__main__':
+ paths = sys.argv[1:]
+
+ urls = [{'loc': loc_from_path(p)} for p in paths if p.endswith('.html')]
+
+ environment = jinja2.Environment(
+ trim_blocks=True,
+ )
+ print(environment.from_string(TEMPLATE).render(root=ROOT, urls=urls))