From 82ed3365fd810cec0ec6ca9d32f07dc7d11d77a2 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 16 Mar 2015 03:08:25 +0300 Subject: [PATCH] gen-sitemap: generate links --- gen-sitemap.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gen-sitemap.py b/gen-sitemap.py index 333069f..32c729d 100755 --- a/gen-sitemap.py +++ b/gen-sitemap.py @@ -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 = '%s' % (subpath, title) if subtree: - subparts.append(indent + "
  • %s" % title) - subparts.append(_tree2html(subtree, level+2)) + subparts.append(indent + "
  • %s" % href) + subparts.append(_tree2html(subtree, subpath, level+2)) subparts.append(indent + "
  • ") else: - subparts.append(indent + "
  • %s
  • " % title) + subparts.append(indent + "
  • %s
  • " % href) s = "\n".join(subparts) parts = [] -- 2.39.5