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

index 088f83819e4c8d491fa0ac69e4eb8ab632c3cb06..aaff97a7c3001f77707b32876da324d3bc20b73a 100755 (executable)
@@ -49,23 +49,24 @@ for dirpath, dirs, files in sorted(os.walk(fullpath)):
         pass
 
 def _tree2html(tree, level=0):
-    indent = "  " * level
-    strings = []
-    strings.append(indent + "<ul>")
-
-    level += 1
-    indent2 = "  " * level
-
+    subparts = []
+    indent = "  " * (level + 1)
     for title, subtree in tree:
         if subtree:
-            strings.append(indent2 + "<li>%s" % title)
-            strings.append(_tree2html(subtree, level+1))
-            strings.append(indent2 + "</li>")
+            subparts.append(indent + "<li>%s" % title)
+            subparts.append(_tree2html(subtree, level+2))
+            subparts.append(indent + "</li>")
         else:
-            strings.append(indent2 + "<li>%s</li>" % title)
+            subparts.append(indent + "<li>%s</li>" % title)
+    s = "\n".join(subparts)
+
+    parts = []
+    indent = "  " * level
+    parts.append(indent + "<ul>")
+    parts.append(s)
+    parts.append(indent + "</ul>")
 
-    strings.append(indent + "</ul>")
-    return '\n'.join(strings)
+    return "\n".join(parts)
 
 sitemap_tmpl = ["""\
 #extends phd_site