From a4401b352150205d2f6ee7e3dc99c1145e399c60 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Wed, 29 Apr 2020 00:40:14 +0200 Subject: Fix links to internal pages Replace .md/.org extension with .html. The output of "make" is now ugly as sin. --- repo/www/Makefile | 6 +++++- repo/www/TODO | 1 - repo/www/convert-internal-links.lua | 21 +++++++++++++++++++++ repo/www/generate-index.py | 5 ++++- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 repo/www/convert-internal-links.lua (limited to 'repo/www') diff --git a/repo/www/Makefile b/repo/www/Makefile index cdc7ee2..db656f2 100644 --- a/repo/www/Makefile +++ b/repo/www/Makefile @@ -43,7 +43,10 @@ $(html_folders) $(cache): $(pages) $(subindices): $(title) $(pages): $(OUT_DIR)/%.html: - pandoc -s $< -o $@ -T "$$(cat $(title))" -M title="$*" + TEXT_FILES="$(TEXT_FILES)" \ + pandoc -s $< -o $@ \ + -T "$$(cat $(title))" -M title="$*" \ + --lua-filter convert-internal-links.lua top_index = $(OUT_DIR)/index.html subindices = $(filter-out $(top_index),$(indices)) @@ -54,6 +57,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: + TEXT_FILES="$(TEXT_FILES)" \ ./generate-index.py $(index_options) $(site_tree) "$(patsubst %/,%,$*)" $@ clean: diff --git a/repo/www/TODO b/repo/www/TODO index 4ac72db..dd1e670 100644 --- a/repo/www/TODO +++ b/repo/www/TODO @@ -1,5 +1,4 @@ - compute "leak count" on toplevel index -- lua filter to s/.md/.html on links - autogenerate nav - autogenerate breadcrumbs - get stylin' diff --git a/repo/www/convert-internal-links.lua b/repo/www/convert-internal-links.lua new file mode 100644 index 0000000..b0817dd --- /dev/null +++ b/repo/www/convert-internal-links.lua @@ -0,0 +1,21 @@ +EXTENSIONS = {} + +string.gsub( + os.getenv("TEXT_FILES"), + "[^%s]+", + function (ext) EXTENSIONS[#EXTENSIONS+1] = ext end +) + +function Link(link) + if link.target:match("^[%w]+://") + then + return link + end + + for _, ext in pairs(EXTENSIONS) + do + link.target = link.target:gsub("%."..ext.."$", ".html") + end + + return link +end diff --git a/repo/www/generate-index.py b/repo/www/generate-index.py index 1fb00e6..4353819 100755 --- a/repo/www/generate-index.py +++ b/repo/www/generate-index.py @@ -97,7 +97,10 @@ def format_index(target, directories, files): def convert_page(content, output, site_title): - pandoc = ('pandoc', '-s', '-o', output) + pandoc = ( + 'pandoc', '-s', '--lua-filter', 'convert-internal-links.lua', + '-o', output + ) if site_title is not None: pandoc += ('-T', site_title) -- cgit v1.2.3