From d0d869e06b30a1f8b7b539978caa0ed6123f9864 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Wed, 26 Aug 2020 00:17:32 +0200 Subject: Add breadcrumbs Likewise, use relative links so that things work when just browsing files locally without a server. Next: tweak or remove redundant titles. --- repo/www/helpers.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'repo/www/helpers.py') 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 = ( + '
  • {crumb}
  • '.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'
  • {current}
  • ' + + return '\n'.join((*crumbs_li, current_li)) -- cgit v1.2.3