summaryrefslogtreecommitdiff
path: root/repo/www/helpers.py
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2020-09-28 19:49:44 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2020-09-28 19:49:44 +0200
commit8822043d6bc93571e400f6e236900a8668a5d724 (patch)
tree49819e64ccc5ba982c2f084acd6cbaf4822b577a /repo/www/helpers.py
parent4e695c301cae8fa2e6d6ab582de2415fc481e1b6 (diff)
parent7bc5ee87b62ab7dffd16913e6864b49e2dbfad06 (diff)
downloadmemory-leaks-8822043d6bc93571e400f6e236900a8668a5d724.tar.xz
Merge branch 'crumbs'
Diffstat (limited to 'repo/www/helpers.py')
-rw-r--r--repo/www/helpers.py40
1 files changed, 34 insertions, 6 deletions
diff --git a/repo/www/helpers.py b/repo/www/helpers.py
index afdb64b..48ebccf 100644
--- a/repo/www/helpers.py
+++ b/repo/www/helpers.py
@@ -56,18 +56,46 @@ def deserialize_directories(directories):
}
-def pandoc(page, output, template, filters, title=None, site_title=None,
- include_after=()):
+def pandoc(page, output, template, filters, stylesheets, include_after=(),
+ variables=None, metadata=None):
cmd = (
'pandoc', '-s', page, '-o', output, '--template', template,
*chain(*(('--lua-filter', f) for f in filters)),
+ *chain(*(('--css', s) for s in stylesheets)),
*chain(*(('--include-after-body', f) for f in include_after))
)
- if title is not 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())
+ ))
+ if metadata is not None:
+ cmd += tuple(chain(
+ *(('-M', f'{k}={v}') for k, v in metadata.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))