X-Git-Url: https://git.phdru.name/?p=phdru.name%2Fphdru.name.git;a=blobdiff_plain;f=gen-sitemap.py;h=088f83819e4c8d491fa0ac69e4eb8ab632c3cb06;hp=b6ab57d8be254160c17af11d82e1fe3282e26498;hb=faa336e3b58a3a51edcfd5da191dc0dcdac3b2be;hpb=deb1c3b89079430679d9cc459a2b272fb004b40c diff --git a/gen-sitemap.py b/gen-sitemap.py index b6ab57d..088f838 100755 --- a/gen-sitemap.py +++ b/gen-sitemap.py @@ -3,6 +3,7 @@ import argparse from fnmatch import fnmatch import os +from news import write_if_changed parser = argparse.ArgumentParser(description='Generate sitemap') parser.add_argument('-x', '--exclude', action='append', @@ -46,3 +47,40 @@ for dirpath, dirs, files in sorted(os.walk(fullpath)): save_level = level except StopIteration: pass + +def _tree2html(tree, level=0): + indent = " " * level + strings = [] + strings.append(indent + "") + return '\n'.join(strings) + +sitemap_tmpl = ["""\ +#extends phd_site +#implements respond +#attr $Title = 'Sitemap' +#attr $Copyright = 2015 +## +#def body_html +"""] + +sitemap_tmpl.append(_tree2html(tree[1])) + +sitemap_tmpl.append(""" +#end def +$phd_site.respond(self) +""") + +write_if_changed("sitemap.tmpl", ''.join(sitemap_tmpl))