From 8692dba921531783b9204a9323db2aba640fe978 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Mon, 20 Apr 2020 00:03:16 +0200 Subject: Parse site title from top-level README Maybe not the best idea, since the dependency chain will trigger a site-wide rebuild everytime the README is edited. Ah well. --- repo/www/Makefile | 15 ++++++++++----- repo/www/print-title.lua | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 repo/www/print-title.lua (limited to 'repo/www') diff --git a/repo/www/Makefile b/repo/www/Makefile index fb933c8..c236936 100644 --- a/repo/www/Makefile +++ b/repo/www/Makefile @@ -1,24 +1,27 @@ TOP_DIR = ../.. OUT_DIR = $(TOP_DIR)/public TEXT_FILES = md org -# make does not care about unpaired single quotes (nor double quotes -# for that matter) but Emacs does. Shell out. -TITLE = $(shell echo "peniblec's memleaks") dirname = $(patsubst %/,%,$(dir $(1))) dirnames = $(sort $(call dirname,$(1))) text_patterns = $(foreach ext,$(TEXT_FILES),'$(TOP_DIR)/**.$(ext)') text_folders = $(call dirnames,$(shell git ls-files $(text_patterns))) +top_readme = $(shell git ls-files $(addprefix $(TOP_DIR)/README.,$(TEXT_FILES))) all: site cache = .cache +# Site title, parsed from the top-level README. +title = $(cache)/title # Maps folders to their contents (files and subfolders). site_tree = $(cache)/site-tree.json # Defines $(pages) and $(indices). dependencies = $(cache)/deps.mk +$(title): $(top_readme) | $(cache) + pandoc --lua-filter print-title.lua $< > $@ + $(site_tree): $(text_folders) | $(cache) ./generate-tree.py -o $@ $(TEXT_FILES) @@ -37,13 +40,15 @@ html_folders = $(call dirnames,$(pages) $(indices)) $(html_folders) $(cache): mkdir -p $@ +$(pages) $(indices): $(title) + $(pages): $(OUT_DIR)/%.html: - pandoc -s $< -o $@ -T "$(TITLE)" -M title="$*" + pandoc -s $< -o $@ -T "$$(cat $(title))" -M title="$*" # ⚠ When tweaking this rule, check whether it still works for the # top-level index.html. $(indices): $(OUT_DIR)/%index.html: - ./generate-index.py $(site_tree) "$(TITLE)" "$(patsubst %/,%,$*)" $@ + ./generate-index.py $(site_tree) "$$(cat $(title))" "$(patsubst %/,%,$*)" $@ clean: -rm $(dependencies) diff --git a/repo/www/print-title.lua b/repo/www/print-title.lua new file mode 100644 index 0000000..c2c90fb --- /dev/null +++ b/repo/www/print-title.lua @@ -0,0 +1,26 @@ +title = '' + +titlefilter = { + Str = function (element) + title = title .. element.text + end, + + Code = function (element) + title = title .. element.text + end, + + Space = function (element) + title = title .. ' ' + end, +} + +function Pandoc(doc) + pandoc.List.map( + doc.meta.title, + function (inline) + pandoc.walk_inline(pandoc.Span(inline), titlefilter) + end + ) + print(title) + os.exit(0) +end -- cgit v1.2.3