From 944a735c39a27fc86569c585f2805837b61adb60 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 2 Aug 2022 20:56:45 +0200 Subject: Slightly tidied up metadata handling --- scripts/metadata.lua | 71 ++++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 50 deletions(-) (limited to 'scripts/metadata.lua') diff --git a/scripts/metadata.lua b/scripts/metadata.lua index a451040..cb6c6e6 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua @@ -1,44 +1,5 @@ local path = require 'pandoc.path' - -function pandoc.List:flatten() - local result = pandoc.List() - - for i = 1, #self do result:extend(self[i]) end - - return result -end - -function pandoc.List:flatMap(fn) - local mapped = self:map(fn) - local result = pandoc.List() - - for i = 1, #mapped do result:extend(mapped[i]) end - - return result -end - -function pandoc.List:take(n) - if n >= #self then return self end - - local result = pandoc.List() - - for i = 1, n do result:insert(self[i]) end - - return result -end - -function dump(o) - if type(o) == 'table' then - local s = '{ ' - for k, v in pairs(o) do - if type(k) ~= 'number' then k = '"' .. k .. '"' end - s = s .. '[' .. k .. '] = ' .. dump(v) .. ',' - end - return s .. '} ' - else - return tostring(o) - end -end +local common = require 'scripts.lib.common' function page_sort(order) return function(p1, p2) @@ -145,13 +106,13 @@ function prep_menu(active_id, main_menu) return { items = items, active = active_item } end -function process_pages(global, order, pages_by_id) +function process_pages(global, build, order, pages_by_id) local pages_all = pandoc.List() local pages_date_desc = pandoc.List() if pages_by_id then for _, page in pairs(pages_by_id) do - local p = process(global, page) + local p = process(global, build, page) if not p.unlisted then pages_all:insert(p) if p.last_update then pages_date_desc:insert(p) end @@ -286,13 +247,13 @@ function generate_list(meta) end end -function process(global, meta) +function process(global, build, meta) meta.namespace = resolve_namespace(meta.namespace) meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") - meta.unlisted = meta.unlisted or (meta.draft and global.mode ~= "dev") + 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, global.file_out, meta.url or meta.file_out) + 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.slug = slug(meta.title) meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork" @@ -304,11 +265,11 @@ function process(global, meta) if meta.feed then if meta.file_out:match(".html$") then meta.feed = { - url = resolve_url(global.site.url, global.file_out, meta.file_out:gsub(".html$", ".xml")), + url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")), } else meta.page = { - url = resolve_url(global.site.url, global.file_out, meta.file_out:gsub(".xml$", ".html")), + url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")), } end end @@ -316,14 +277,14 @@ function process(global, meta) if meta.thumbnail then meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), meta.file_out) - meta.thumbnail = resolve_url(global.site.url, global.file_out, meta.thumbnail) + 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 - meta.pages = process_pages(global, meta.list_order, meta.pages) + 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)) if meta.last_update then @@ -348,8 +309,18 @@ function process(global, meta) end function Meta(meta) + local build = {} + + for key, value in pairs(meta) do + local suffix = key:match('^build.(.*)$') + + if suffix then + build[suffix] = value + end + end + meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") find_depth(meta) - return process(meta, meta) + return process(meta, build, meta) end -- cgit v1.2.3-54-g00ecf