diff options
Diffstat (limited to 'repo')
| -rw-r--r-- | repo/www/Makefile | 11 | ||||
| -rw-r--r-- | repo/www/convert-internal-links.lua | 10 | ||||
| -rwxr-xr-x | repo/www/generate-lua-config.py | 34 | ||||
| -rw-r--r-- | repo/www/helpers.py | 3 |
4 files changed, 46 insertions, 12 deletions
diff --git a/repo/www/Makefile b/repo/www/Makefile index f88672c..aa48971 100644 --- a/repo/www/Makefile +++ b/repo/www/Makefile @@ -23,6 +23,8 @@ cache = .cache title = $(cache)/title # Maps folders to their contents (files and subfolders). site_tree = $(cache)/site-tree.json +# Lua module to let filters know about the configuration. +lua_config = $(cache)/config.lua # Defines $(pages) and $(indices). dependencies = $(cache)/deps.mk @@ -32,6 +34,9 @@ $(title): $(top_readme) | $(cache) $(site_tree): $(page_folders) | $(cache) ./generate-tree.py -o $@ $(EXTENSIONS) +$(lua_config): | $(cache) + ./generate-lua-config.py EXTENSIONS="$(EXTENSIONS)" > $@ + $(dependencies): $(site_tree) | $(cache) ./generate-deps.py $< $@ $(OUT_DIR) @@ -49,10 +54,10 @@ $(html_folders) $(cache): $(pages) $(subindices): $(title) -$(pages) $(indices): $(html_template) +$(pages) $(indices): $(html_template) $(lua_filters) $(lua_config) $(pages): $(OUT_DIR)/%.html: - $(call v,PAGE,$*) EXTENSIONS="$(EXTENSIONS)" \ + $(call v,PAGE,$*) \ ./generate-page.py --site-title="$$(cat $(title))" --title="$*" \ $(foreach f,$(lua_filters),--lua-filter $(f)) \ --template=$(html_template) $< $@ @@ -66,7 +71,7 @@ $(subindices): index_options = --site-title="$$(cat $(title))" # ⚠ When tweaking this rule, check whether it still works for the # top-level index.html. $(indices): $(OUT_DIR)/%index.html: - $(call v,INDEX,$*) EXTENSIONS="$(EXTENSIONS)" \ + $(call v,INDEX,$*) \ ./generate-index.py $(index_options) --template=$(html_template) \ $(foreach f,$(lua_filters),--lua-filter $(f)) \ $(site_tree) "$(patsubst %/,%,$*)" $@ diff --git a/repo/www/convert-internal-links.lua b/repo/www/convert-internal-links.lua index e50352a..21054d1 100644 --- a/repo/www/convert-internal-links.lua +++ b/repo/www/convert-internal-links.lua @@ -1,10 +1,4 @@ -EXTENSIONS = {} - -string.gsub( - os.getenv("EXTENSIONS"), - "[^%s]+", - function (ext) EXTENSIONS[#EXTENSIONS+1] = ext end -) +local config = require 'config' function Link(link) if link.target:match("^[%w]+://") @@ -12,7 +6,7 @@ function Link(link) return link end - for _, ext in pairs(EXTENSIONS) + for _, ext in pairs(config.EXTENSIONS) do link.target = link.target:gsub("%."..ext.."$", ".html") end diff --git a/repo/www/generate-lua-config.py b/repo/www/generate-lua-config.py new file mode 100755 index 0000000..0a00443 --- /dev/null +++ b/repo/www/generate-lua-config.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +from sys import argv + + +TEMPLATE = '''\ +local config = {{}} + +config.EXTENSIONS = {{ {EXTENSIONS} }} + +return config +''' + + +def _quote(s): + return f"'{s}'" + + +def main(arguments): + pairs = (arg.split('=') for arg in arguments) + + formatters = { + 'EXTENSIONS': lambda v: ', '.join(map(_quote, v.split())) + } + + parameters = { + key: formatters[key](value) for (key, value) in pairs + } + + print(TEMPLATE.format_map(parameters), end='') + + +if __name__ == '__main__': + main(argv[1:]) diff --git a/repo/www/helpers.py b/repo/www/helpers.py index 434ef6c..f76fa02 100644 --- a/repo/www/helpers.py +++ b/repo/www/helpers.py @@ -1,7 +1,7 @@ from collections import defaultdict from dataclasses import dataclass, field from itertools import chain -from os import path +from os import environ, path from subprocess import run from typing import Iterator @@ -67,4 +67,5 @@ def pandoc(page, output, template, filters, title=None, site_title=None): if site_title is not None: cmd += ('-T', site_title) + environ['LUA_PATH'] = '.cache/?.lua;;' run(cmd, check=True) |
