summaryrefslogtreecommitdiff
path: root/repo
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
parent4e695c301cae8fa2e6d6ab582de2415fc481e1b6 (diff)
parent7bc5ee87b62ab7dffd16913e6864b49e2dbfad06 (diff)
downloadmemory-leaks-8822043d6bc93571e400f6e236900a8668a5d724.tar.xz
Merge branch 'crumbs'
Diffstat (limited to 'repo')
-rw-r--r--repo/www/Makefile19
-rw-r--r--repo/www/TODO2
-rw-r--r--repo/www/crumbs.css32
-rwxr-xr-xrepo/www/generate-index.py42
-rwxr-xr-xrepo/www/generate-page.py22
-rw-r--r--repo/www/helpers.py40
-rw-r--r--repo/www/template.html11
7 files changed, 139 insertions, 29 deletions
diff --git a/repo/www/Makefile b/repo/www/Makefile
index aa48971..9a2c90e 100644
--- a/repo/www/Makefile
+++ b/repo/www/Makefile
@@ -14,6 +14,7 @@ page_patterns = $(foreach ext,$(EXTENSIONS),'$(TOP_DIR)/**.$(ext)')
page_folders = $(call dirnames,$(shell git ls-files $(page_patterns)))
top_readme = $(shell git ls-files $(addprefix $(TOP_DIR)/README.,$(EXTENSIONS)))
html_template = template.html
+stylesheets_src = crumbs.css
lua_filters = convert-internal-links.lua
all: site
@@ -42,14 +43,20 @@ $(dependencies): $(site_tree) | $(cache)
include $(dependencies)
-site: $(pages) $(indices)
+stylesheets_dir = $(OUT_DIR)/style
+stylesheets = $(foreach s,$(stylesheets_src),$(stylesheets_dir)/$(s))
+
+site: $(pages) $(indices) $(stylesheets)
# List of output folders. Compute this from the full list of HTML
# pages, since $(page_folders) may be missing some intermediate
# directories (e.g. folders that only contain subfolders).
html_folders = $(call dirnames,$(pages) $(indices))
-$(html_folders) $(cache):
+top_index = $(OUT_DIR)/index.html
+subindices = $(filter-out $(top_index),$(indices))
+
+$(html_folders) $(stylesheets_dir) $(cache):
mkdir -p $@
$(pages) $(subindices): $(title)
@@ -60,11 +67,9 @@ $(pages): $(OUT_DIR)/%.html:
$(call v,PAGE,$*) \
./generate-page.py --site-title="$$(cat $(title))" --title="$*" \
$(foreach f,$(lua_filters),--lua-filter $(f)) \
+ $(foreach s,$(stylesheets_src),--stylesheet style/$(s)) \
--template=$(html_template) $< $@
-top_index = $(OUT_DIR)/index.html
-subindices = $(filter-out $(top_index),$(indices))
-
$(top_index): index_options =
$(subindices): index_options = --site-title="$$(cat $(title))"
@@ -74,8 +79,12 @@ $(indices): $(OUT_DIR)/%index.html:
$(call v,INDEX,$*) \
./generate-index.py $(index_options) --template=$(html_template) \
$(foreach f,$(lua_filters),--lua-filter $(f)) \
+ $(foreach s,$(stylesheets_src),--stylesheet style/$(s)) \
$(site_tree) "$(patsubst %/,%,$*)" $@
+$(stylesheets): $(stylesheets_dir)/%.css: %.css | $(stylesheets_dir)
+ cp $< $@
+
clean:
-rm -r $(cache)
-rm -r $(OUT_DIR)
diff --git a/repo/www/TODO b/repo/www/TODO
index 46772b8..7eac4fe 100644
--- a/repo/www/TODO
+++ b/repo/www/TODO
@@ -6,8 +6,6 @@
- convert properties
- convert tags
- compute "leak count" on toplevel index
-- autogenerate nav
-- autogenerate breadcrumbs
- get stylin'
- pandoc template
- tufte css? at least sidenotes rather than footnotes
diff --git a/repo/www/crumbs.css b/repo/www/crumbs.css
new file mode 100644
index 0000000..acbe4f1
--- /dev/null
+++ b/repo/www/crumbs.css
@@ -0,0 +1,32 @@
+nav.breadcrumb ol {
+ padding-left: 0;
+}
+
+nav.breadcrumb li {
+ /* Prefer inline-block to inline, to prevent wrapping inside
+ * individual crumbs.
+ */
+ display: inline-block;
+}
+
+/* Prefer
+ * li:not(:last-child)::after
+ * to
+ * li + li::before
+ * as I want crumbs and slashes to wrap like this:
+ * foo / bar /
+ * baz
+ * rather than like that:
+ * foo / bar
+ * / baz
+ */
+nav.breadcrumb li:not(:last-child)::after {
+ margin-left: 0.25em;
+ height: 0.8em;
+ font-weight: bold;
+ content: '/';
+}
+
+nav.breadcrumb li[aria-current="page"] {
+ font-weight: bold;
+}
diff --git a/repo/www/generate-index.py b/repo/www/generate-index.py
index 116a454..16d1874 100755
--- a/repo/www/generate-index.py
+++ b/repo/www/generate-index.py
@@ -3,13 +3,14 @@
from argparse import ArgumentParser
from itertools import chain
import json
+from os import path
from pathlib import Path
from subprocess import run
from tempfile import NamedTemporaryFile
from git import Repo
-from helpers import deserialize_directories, pandoc
+from helpers import deserialize_directories, generate_crumbs, pandoc
def parse_arguments():
@@ -25,6 +26,10 @@ def parse_arguments():
help='Lua filter to run the page through.'
)
parser.add_argument(
+ '--stylesheet', dest='css', action='append',
+ help='CSS stylesheet to link to.'
+ )
+ parser.add_argument(
'site_tree', help='JSON file describing the page tree.'
)
parser.add_argument(
@@ -87,9 +92,16 @@ def main(arguments):
folders, files = list_files(arguments.site_tree, target)
pages, readme = list_pages(files)
+ toc_title = f'Index for {target}' if target else 'Index'
html_toc = format_toc(folders, pages)
- index_title = f'Index for {target}' if target else 'Index'
+ path_to_top = path.relpath('.', start=target)
+ stylesheets = (path.join(path_to_top, s) for s in arguments.css)
+
+ variables = {'crumbs': generate_crumbs(Path(target)/'index')}
+ metadata = {}
+ if arguments.site_title is not None:
+ metadata['sitetitle'] = arguments.site_title
if readme is not None:
repo_top = Repo(search_parent_directories=True).working_dir
@@ -97,16 +109,20 @@ def main(arguments):
# If the README doesn't have a title, give a default to pandoc
# out-of-band.
- page_title = None if has_title(readme_path) else 'README'
+ if not has_title(readme_path):
+ metadata['pagetitle'] = target or 'README'
with NamedTemporaryFile(mode='w+') as toc:
- toc.write('<h1>{title}</h1>\n'.format(title=index_title))
+ toc.write(f'<h1>{toc_title}</h1>\n')
toc.write(html_toc)
toc.flush()
- pandoc(readme_path, arguments.output, arguments.template,
- arguments.filters, site_title=arguments.site_title,
- title=page_title, include_after=(toc.name,))
+ pandoc(
+ readme_path, arguments.output,
+ arguments.template, arguments.filters, stylesheets,
+ include_after=(toc.name,),
+ variables=variables, metadata=metadata
+ )
return
with NamedTemporaryFile(suffix='.md') as dummy_readme, \
@@ -114,9 +130,15 @@ def main(arguments):
toc.write(html_toc)
toc.flush()
- pandoc(dummy_readme.name, arguments.output, arguments.template,
- arguments.filters, site_title=arguments.site_title,
- title=index_title, include_after=(toc.name,))
+ metadata['pagetitle'] = toc_title
+ metadata['title'] = 'Index'
+
+ pandoc(
+ dummy_readme.name, arguments.output,
+ arguments.template, arguments.filters, stylesheets,
+ include_after=(toc.name,),
+ variables=variables, metadata=metadata
+ )
if __name__ == '__main__':
diff --git a/repo/www/generate-page.py b/repo/www/generate-page.py
index c9fa0e4..cb2317b 100755
--- a/repo/www/generate-page.py
+++ b/repo/www/generate-page.py
@@ -1,8 +1,12 @@
#!/usr/bin/env python3
from argparse import ArgumentParser
+from os import path
+from pathlib import Path
-from helpers import pandoc
+from git import Repo
+
+from helpers import generate_crumbs, pandoc
def parse_arguments():
@@ -18,6 +22,10 @@ def parse_arguments():
help='Lua filter to run the page through.'
)
parser.add_argument(
+ '--stylesheet', dest='css', action='append',
+ help='CSS stylesheet to link to.'
+ )
+ parser.add_argument(
'--title', help='Page title.'
)
parser.add_argument(
@@ -30,13 +38,21 @@ def parse_arguments():
def main(arguments):
+ repo_top = Repo(search_parent_directories=True).working_dir
+ path_to_top = path.relpath(repo_top, path.dirname(arguments.page))
+ stylesheets = (path.join(path_to_top, s) for s in arguments.css)
+
+ page_path = Path(arguments.page).resolve().relative_to(repo_top)
+
pandoc(
arguments.page,
arguments.output,
arguments.template,
arguments.filters,
- title=arguments.title,
- site_title=arguments.site_title
+ stylesheets,
+ variables={'crumbs': generate_crumbs(page_path)},
+ metadata={'pagetitle': arguments.title,
+ 'sitetitle': arguments.site_title}
)
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))
diff --git a/repo/www/template.html b/repo/www/template.html
index 724cde4..b4746d9 100644
--- a/repo/www/template.html
+++ b/repo/www/template.html
@@ -13,7 +13,7 @@ $endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
$endif$
- <title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>
+ <title>$pagetitle$$if(sitetitle)$ – $sitetitle$$endif$</title>
<style>
$styles.html()$
</style>
@@ -31,9 +31,15 @@ $endfor$
$for(include-before)$
$include-before$
$endfor$
-$if(title)$
<header id="title-block-header">
+<nav class="breadcrumb" aria-label="Breadcrumb">
+<ol>
+$crumbs$
+</ol>
+</nav>
+$if(title)$
<h1 class="title">$title$</h1>
+$endif$
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
@@ -44,7 +50,6 @@ $if(date)$
<p class="date">$date$</p>
$endif$
</header>
-$endif$
$if(toc)$
<nav id="$idprefix$TOC" role="doc-toc">
$if(toc-title)$