]> git.phdru.name Git - phdru.name/phdru.name.git/commitdiff
gen-sitemap: generate links
authorOleg Broytman <phd@phdru.name>
Mon, 16 Mar 2015 00:08:25 +0000 (03:08 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 23 Dec 2015 15:54:10 +0000 (18:54 +0300)
gen-sitemap.py

index 333069f0122df57fdad96776356d9ed175467509..32c729dfabefcc7d9047e9c2a442aaae46bb8ed6 100755 (executable)
@@ -49,16 +49,20 @@ for dirpath, dirs, files in sorted(os.walk(fullpath)):
     except StopIteration:
         pass
 
-def _tree2html(tree, level=0):
+def _tree2html(tree, path='', level=0):
     subparts = []
     indent = "  " * (level + 1)
     for title, subtree in tree:
+        subpath = "%s/%s" % (path, title)
+        if subpath.startswith('/'):
+            subpath = subpath[1:]
+        href = '<a href="%s/">%s</a>' % (subpath, title)
         if subtree:
-            subparts.append(indent + "<li>%s" % title)
-            subparts.append(_tree2html(subtree, level+2))
+            subparts.append(indent + "<li>%s" % href)
+            subparts.append(_tree2html(subtree, subpath, level+2))
             subparts.append(indent + "</li>")
         else:
-            subparts.append(indent + "<li>%s</li>" % title)
+            subparts.append(indent + "<li>%s</li>" % href)
     s = "\n".join(subparts)
 
     parts = []