diff options
author | Ethel Morgan <eth@ethulhu.co.uk> | 2020-07-06 18:23:10 +0100 |
---|---|---|
committer | Ethel Morgan <eth@ethulhu.co.uk> | 2020-07-06 18:23:10 +0100 |
commit | b1e6491f77421ae4623391a7f53af7f3e6c13f34 (patch) | |
tree | acc4ce7ae214b92dbf2c269c70e94b68dac1d640 /generate-sitemap | |
parent | 04be5845dbaa6f8dec45a80dbe199861608b96f2 (diff) |
import website from previous repo
Diffstat (limited to '')
-rwxr-xr-x | generate-sitemap | 40 |
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)) |