]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
gen-sitemap: generate simple html
authorOleg Broytman <phd@phdru.name>
Sun, 15 Mar 2015 23:14:05 +0000 (02:14 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 23 Dec 2015 15:54:10 +0000 (18:54 +0300)
gen-sitemap.py

index b6ab57d8be254160c17af11d82e1fe3282e26498..63b34a2ff5ce9af1df3e161410d56205de97d76b 100755 (executable)
@@ -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,24 @@ 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 + "<ul>")
+
+    level += 1
+    indent2 = "  " * level
+
+    for title, subtree in tree:
+        if subtree:
+            strings.append(indent2 + "<li>%s" % title)
+            strings.append(_tree2html(subtree, level+1))
+            strings.append(indent2 + "</li>")
+        else:
+            strings.append(indent2 + "<li>%s</li>" % title)
+
+    strings.append(indent + "</ul>")
+    return '\n'.join(strings)
+
+write_if_changed("sitemap.html", _tree2html(tree[1]))