blob: 998b9eca3aa9980cbbde27fa7de7f16e6b495657 (
plain)
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
|
#!/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))
|