diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | scripts/subpages.lua | 25 |
2 files changed, 29 insertions, 1 deletions
@@ -47,7 +47,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ | |||
47 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ | 47 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ |
48 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) | 48 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) |
49 | 49 | ||
50 | .cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) scripts/subpages.jq scripts/metadata_tpl.json | .cache/meta | 50 | .cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) scripts/subpages.lua scripts/subpages.jq scripts/metadata_tpl.json | .cache/meta |
51 | $(info [META] $< -> $@) | 51 | $(info [META] $< -> $@) |
52 | 52 | ||
53 | mkdir -p $(@D) | 53 | mkdir -p $(@D) |
@@ -66,6 +66,9 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ | |||
66 | pandoc \ | 66 | pandoc \ |
67 | -f markdown-citations \ | 67 | -f markdown-citations \ |
68 | -t html5 \ | 68 | -t html5 \ |
69 | --lua-filter scripts/subpages.lua \ | ||
70 | $(GLOBAL_METADATA) \ | ||
71 | --metadata namespace="$(NAMESPACE)" \ | ||
69 | -o "$@.content" "$<" | 72 | -o "$@.content" "$<" |
70 | jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" | 73 | jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" |
71 | rm "$@.pages" | 74 | rm "$@.pages" |
diff --git a/scripts/subpages.lua b/scripts/subpages.lua new file mode 100644 index 0000000..95f68f5 --- /dev/null +++ b/scripts/subpages.lua | |||
@@ -0,0 +1,25 @@ | |||
1 | local path = require 'pandoc.path' | ||
2 | |||
3 | local namespace = '' | ||
4 | local siteUrl = '' | ||
5 | |||
6 | function meta(meta) | ||
7 | namespace = pandoc.utils.stringify(meta.namespace) | ||
8 | siteUrl = pandoc.utils.stringify(meta.site.url):gsub("/$", "") | ||
9 | end | ||
10 | |||
11 | function image(el) | ||
12 | if path.is_relative(el.src) then el.src = siteUrl .. path.join({ namespace, el.src }) end | ||
13 | |||
14 | return el | ||
15 | end | ||
16 | |||
17 | function link(el) | ||
18 | if path.is_relative(el.target) then | ||
19 | el.target = siteUrl .. path.join({ namespace, el.target }) | ||
20 | end | ||
21 | |||
22 | return el | ||
23 | end | ||
24 | |||
25 | return { { Meta = meta }, { Image = image, Link = link } } | ||