From 93911faccb27ac11f3d4a1fdc098ebb6255d5612 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 3 Aug 2022 16:23:32 +0200 Subject: Website gen adjustments --- Makefile | 18 ++++++---- scripts/metadata.lua | 89 ++++++++++++++++++++++++----------------------- scripts/pages_content.lua | 27 ++++++++++++++ scripts/subpages.lua | 27 -------------- 4 files changed, 83 insertions(+), 78 deletions(-) create mode 100644 scripts/pages_content.lua delete mode 100644 scripts/subpages.lua diff --git a/Makefile b/Makefile index 863fca1..52a90f9 100644 --- a/Makefile +++ b/Makefile @@ -50,13 +50,13 @@ 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,$$@,)) filters/*.lua scripts/subpages.lua scripts/subpages.jq scripts/metadata.json | .cache/meta +.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) filters/*.lua scripts/pages_content.lua scripts/subpages.jq scripts/metadata.json | .cache/meta $(info [META] $< -> $@) mkdir -p $(@D) $(eval PAGES_FILES = $(filter .cache/meta/%.json,$^)) $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) - $(if $(PAGES_FILES),jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES) > "$@.pages",echo "{}" > "$@.pages") + $(if $(PAGES_FILES),jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES) > "$@.pages",echo "{ \"pages\": [] }" > "$@.pages") pandoc \ -f markdown-citations-implicit_figures \ -t html5 \ @@ -65,7 +65,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ --metadata-file "$@.pages" \ --template scripts/metadata.json \ --metadata namespace="$(NAMESPACE)" \ - --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ + --metadata file_out="$(patsubst .cache/meta/%.json,/%.html,$@)" \ $(PANDOC_FILTERS) \ -o "$@.meta" "$<" rm "$@.pages" @@ -74,11 +74,11 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ -t html5 \ --wrap preserve \ --lua-filter scripts/metadata.lua \ - --lua-filter scripts/subpages.lua \ + --lua-filter scripts/pages_content.lua \ $(GLOBAL_METADATA) \ --metadata-file "$@.meta" \ --metadata build.mode="$(MODE)" \ - --metadata build.file_out="$@" \ + --metadata build.file_out="$(patsubst .cache/meta/%.json,/%.html,$@)" \ $(PANDOC_FILTERS) \ -o "$@.content" "$<" jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" @@ -92,6 +92,7 @@ out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLAT $(info [MARK] $< -> $@) mkdir -p $(@D) + $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) pandoc \ -f markdown-citations-implicit_figures \ -t html5 \ @@ -103,7 +104,8 @@ out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLAT --metadata-file .cache/assets.json \ --metadata-file "$(filter .cache/meta/%.json,$^)" \ --metadata build.mode="$(MODE)" \ - --metadata build.file_out="$@" \ + --metadata build.namespace="$(NAMESPACE)" \ + --metadata build.file_out="$(patsubst out/%,/%,$@)" \ $(PANDOC_FILTERS) \ -o "$@" "$<" @@ -111,6 +113,7 @@ out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml $(info [FEED] $< -> $@) mkdir -p $(@D) + $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) pandoc \ -f markdown-citations-implicit_figures \ -t html5 \ @@ -121,7 +124,8 @@ out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml $(GLOBAL_METADATA) \ --metadata-file "$(filter .cache/meta/%.json,$^)" \ --metadata build.mode="$(MODE)" \ - --metadata build.file_out="$@" \ + --metadata build.namespace="$(NAMESPACE)" \ + --metadata build.file_out="$(patsubst out/%,/%,$@)" \ $(PANDOC_FILTERS) \ -o "$@" "$<" diff --git a/scripts/metadata.lua b/scripts/metadata.lua index cb6c6e6..7d9206f 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua @@ -111,8 +111,8 @@ function process_pages(global, build, order, pages_by_id) local pages_date_desc = pandoc.List() if pages_by_id then - for _, page in pairs(pages_by_id) do - local p = process(global, build, page) + for _, p in pairs(pages_by_id) do + process(global, build, p) if not p.unlisted then pages_all:insert(p) if p.last_update then pages_date_desc:insert(p) end @@ -133,19 +133,35 @@ function find_depth(meta) local depth = 0 - if meta.pages then - for _, page in pairs(meta.pages) do - local p = find_depth(page) - if not p.unlisted then - local d = p.depth + 1 - if d > depth then depth = d end - end + for _, p in pairs(meta.pages) do + find_depth(p) + if not p.unlisted then + local d = p.depth + 1 + if d > depth then depth = d end end end meta.depth = depth +end - return meta +function resolve_urls(global, build, meta) + meta.url = resolve_url(global.site.url, build.file_out, meta.url) + + if meta.feed then + if meta.file_out:match(".html$") then + meta.feed = { + url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")), + } + else + meta.page = { + url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")), + } + end + end + + if meta.thumbnail then + meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) + end end function d1_page_to_list_item(meta, p) @@ -249,40 +265,20 @@ end function process(global, build, meta) meta.namespace = resolve_namespace(meta.namespace) - meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") + meta.file_out = pandoc.utils.stringify(meta.file_out) meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") meta.redirect = meta.url and true - meta.url = meta.url and pandoc.utils.stringify(meta.url) - meta.url = resolve_url(global.site.url, build.file_out, meta.url or meta.file_out) - meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" + meta.url = meta.url and pandoc.utils.stringify(meta.url) or meta.file_out + meta.title = meta.title and pandoc.utils.stringify(meta.title) or "" meta.slug = slug(meta.title) - meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork" - if meta.list_order then meta.list_order = pandoc.utils.stringify(meta.list_order) end + meta.schema_type = meta.schema_type and pandoc.utils.stringify(meta.schema_type) or "CreativeWork" + meta.list_order = meta.list_order and pandoc.utils.stringify(meta.list_order) meta.list_layout = prep_layout(meta.list_layout or "list") - if meta.list_limit then meta.list_limit = tonumber(pandoc.utils.stringify(meta.list_limit)) end - if meta.position then meta.position = tonumber(pandoc.utils.stringify(meta.position)) end + meta.list_limit = meta.list_limit and tonumber(pandoc.utils.stringify(meta.list_limit)) + meta.position = meta.position and tonumber(pandoc.utils.stringify(meta.position)) + meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), meta.file_out) - if meta.feed then - if meta.file_out:match(".html$") then - meta.feed = { - url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")), - } - else - meta.page = { - url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")), - } - end - end - - if meta.thumbnail then - meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), - meta.file_out) - meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) - end - - if meta.menus and meta.menus.main then - meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) - end + resolve_urls(global, build, meta) meta.pages = process_pages(global, build, meta.list_order, meta.pages) meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) @@ -302,10 +298,6 @@ function process(global, build, meta) end meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd - - meta.list = generate_list(meta) - - return meta end function Meta(meta) @@ -316,11 +308,20 @@ function Meta(meta) if suffix then build[suffix] = value + meta[key] = nil end end meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") find_depth(meta) - return process(meta, build, meta) + process(meta, build, meta) + + meta.list = generate_list(meta) + + if meta.menus and meta.menus.main then + meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) + end + + return meta end diff --git a/scripts/pages_content.lua b/scripts/pages_content.lua new file mode 100644 index 0000000..b753b1e --- /dev/null +++ b/scripts/pages_content.lua @@ -0,0 +1,27 @@ +local path = require 'pandoc.path' + +local namespace = '' +local siteUrl = '' + +function meta(meta) + namespace = pandoc.utils.stringify(meta.namespace.full) + siteUrl = pandoc.utils.stringify(meta.site.url):gsub("/$", "") +end + +function image(el) + if path.is_relative(el.src) and not el.src:match("^https?://") then + el.src = siteUrl .. path.join({ namespace, el.src }) + end + + return el +end + +function link(el) + if path.is_relative(el.target) and not el.target:match("^https?://") then + el.target = siteUrl .. path.join({ namespace, el.target }) + end + + return el +end + +return { { Meta = meta }, { Image = image, Link = link } } diff --git a/scripts/subpages.lua b/scripts/subpages.lua deleted file mode 100644 index b753b1e..0000000 --- a/scripts/subpages.lua +++ /dev/null @@ -1,27 +0,0 @@ -local path = require 'pandoc.path' - -local namespace = '' -local siteUrl = '' - -function meta(meta) - namespace = pandoc.utils.stringify(meta.namespace.full) - siteUrl = pandoc.utils.stringify(meta.site.url):gsub("/$", "") -end - -function image(el) - if path.is_relative(el.src) and not el.src:match("^https?://") then - el.src = siteUrl .. path.join({ namespace, el.src }) - end - - return el -end - -function link(el) - if path.is_relative(el.target) and not el.target:match("^https?://") 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