summaryrefslogtreecommitdiff
path: root/repo/www/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'repo/www/helpers.py')
-rw-r--r--repo/www/helpers.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/repo/www/helpers.py b/repo/www/helpers.py
index 9b97902..80b8857 100644
--- a/repo/www/helpers.py
+++ b/repo/www/helpers.py
@@ -57,7 +57,7 @@ def deserialize_directories(directories):
def pandoc(page, output, template, filters, stylesheets, title=None,
- site_title=None, include_after=()):
+ site_title=None, include_after=(), variables=None):
cmd = (
'pandoc', '-s', page, '-o', output, '--template', template,
*chain(*(('--lua-filter', f) for f in filters)),
@@ -69,6 +69,33 @@ def pandoc(page, output, template, filters, stylesheets, title=None,
cmd += ('-M', f'title={title}')
if site_title is not None:
cmd += ('-T', site_title)
+ if variables is not None:
+ cmd += tuple(chain(
+ *(('-V', f'{k}={v}') for k, v in variables.items())
+ ))
environ['LUA_PATH'] = '.cache/?.lua;;'
run(cmd, check=True)
+
+
+def generate_crumbs(target):
+ parts = ('(top)', *target.parts)
+
+ if parts[-1] == 'index':
+ *crumbs, current = parts[:-1]
+ else:
+ crumbs = parts[:-1]
+ current, _ = path.splitext(parts[-1])
+
+ crumbs_li = (
+ '<li><a href="{link}">{crumb}</a></li>'.format(
+ link=(path.relpath(path.join(*crumbs[1:i], 'index.html'),
+ start=target.parent)),
+ crumb=crumb
+ )
+ for i, crumb in enumerate(crumbs, start=1)
+ )
+
+ current_li = f'<li aria-current="page">{current}</li>'
+
+ return '\n'.join((*crumbs_li, current_li))