diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2020-08-25 23:12:57 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2020-08-25 23:12:57 +0200 |
| commit | 79f3257437636c153bd9e66131495680ddf39afd (patch) | |
| tree | 1cad94f6d156f6d05bd3843fd819ca30238b8d28 | |
| parent | ef1cb64a6cfda2b971649ee5cf051e50235f081e (diff) | |
| download | memory-leaks-79f3257437636c153bd9e66131495680ddf39afd.tar.xz | |
Include stylesheets
With relative links, so that I can just view HTML files on my disk
without spawning a webserver.
| -rw-r--r-- | repo/www/Makefile | 13 | ||||
| -rwxr-xr-x | repo/www/generate-index.py | 22 | ||||
| -rwxr-xr-x | repo/www/generate-page.py | 12 | ||||
| -rw-r--r-- | repo/www/helpers.py | 5 |
4 files changed, 43 insertions, 9 deletions
diff --git a/repo/www/Makefile b/repo/www/Makefile index aa48971..86d1d98 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 = lua_filters = convert-internal-links.lua all: site @@ -42,14 +43,17 @@ $(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) $(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): +$(html_folders) $(stylesheets_dir) $(cache): mkdir -p $@ $(pages) $(subindices): $(title) @@ -60,6 +64,7 @@ $(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 @@ -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/generate-index.py b/repo/www/generate-index.py index 116a454..d615756 100755 --- a/repo/www/generate-index.py +++ b/repo/www/generate-index.py @@ -3,6 +3,7 @@ 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 @@ -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( @@ -89,7 +94,14 @@ def main(arguments): html_toc = format_toc(folders, pages) - index_title = f'Index for {target}' if target else 'Index' + if target: + index_title = f'Index for {target}' + path_to_top = path.relpath('.', target) + else: + index_title = 'Index' + path_to_top = '.' + + stylesheets = (path.join(path_to_top, s) for s in arguments.css) if readme is not None: repo_top = Repo(search_parent_directories=True).working_dir @@ -105,8 +117,8 @@ def main(arguments): toc.flush() pandoc(readme_path, arguments.output, arguments.template, - arguments.filters, site_title=arguments.site_title, - title=page_title, include_after=(toc.name,)) + arguments.filters, stylesheets, title=page_title, + site_title=arguments.site_title, include_after=(toc.name,)) return with NamedTemporaryFile(suffix='.md') as dummy_readme, \ @@ -115,8 +127,8 @@ def main(arguments): toc.flush() pandoc(dummy_readme.name, arguments.output, arguments.template, - arguments.filters, site_title=arguments.site_title, - title=index_title, include_after=(toc.name,)) + arguments.filters, stylesheets, title=index_title, + site_title=arguments.site_title, include_after=(toc.name,)) if __name__ == '__main__': diff --git a/repo/www/generate-page.py b/repo/www/generate-page.py index c9fa0e4..e200a9e 100755 --- a/repo/www/generate-page.py +++ b/repo/www/generate-page.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 from argparse import ArgumentParser +from os import path + +from git import Repo from helpers import pandoc @@ -18,6 +21,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,11 +37,16 @@ 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) + pandoc( arguments.page, arguments.output, arguments.template, arguments.filters, + stylesheets, title=arguments.title, site_title=arguments.site_title ) diff --git a/repo/www/helpers.py b/repo/www/helpers.py index afdb64b..9b97902 100644 --- a/repo/www/helpers.py +++ b/repo/www/helpers.py @@ -56,11 +56,12 @@ def deserialize_directories(directories): } -def pandoc(page, output, template, filters, title=None, site_title=None, - include_after=()): +def pandoc(page, output, template, filters, stylesheets, title=None, + site_title=None, include_after=()): 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)) ) |
