diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2020-08-26 00:17:32 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2020-08-28 17:08:45 +0200 |
| commit | d0d869e06b30a1f8b7b539978caa0ed6123f9864 (patch) | |
| tree | 462cde345af47d85ee148286deb33bd5af041d92 /repo/www/helpers.py | |
| parent | 79f3257437636c153bd9e66131495680ddf39afd (diff) | |
| download | memory-leaks-d0d869e06b30a1f8b7b539978caa0ed6123f9864.tar.xz | |
Add breadcrumbs
Likewise, use relative links so that things work when just browsing
files locally without a server.
Next: tweak or remove redundant titles.
Diffstat (limited to 'repo/www/helpers.py')
| -rw-r--r-- | repo/www/helpers.py | 29 |
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)) |
