From 5320823ae5775b1857ba232262cdeb06c4ffbb6b Mon Sep 17 00:00:00 2001 From: Volpeon Date: Fri, 17 Dec 2021 15:23:34 +0100 Subject: Use full image URLs in feeds --- Makefile | 5 ++++- scripts/subpages.lua | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 scripts/subpages.lua diff --git a/Makefile b/Makefile index 8846a3e..ae1e75d 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) -.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) scripts/subpages.jq scripts/metadata_tpl.json | .cache/meta +.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) scripts/subpages.lua scripts/subpages.jq scripts/metadata_tpl.json | .cache/meta $(info [META] $< -> $@) mkdir -p $(@D) @@ -66,6 +66,9 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ pandoc \ -f markdown-citations \ -t html5 \ + --lua-filter scripts/subpages.lua \ + $(GLOBAL_METADATA) \ + --metadata namespace="$(NAMESPACE)" \ -o "$@.content" "$<" jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" 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 @@ +local path = require 'pandoc.path' + +local namespace = '' +local siteUrl = '' + +function meta(meta) + namespace = pandoc.utils.stringify(meta.namespace) + siteUrl = pandoc.utils.stringify(meta.site.url):gsub("/$", "") +end + +function image(el) + if path.is_relative(el.src) then el.src = siteUrl .. path.join({ namespace, el.src }) end + + return el +end + +function link(el) + if path.is_relative(el.target) then + el.target = siteUrl .. path.join({ namespace, el.target }) + end + + return el +end + +return { { Meta = meta }, { Image = image, Link = link } } -- cgit v1.2.3-54-g00ecf