From 93911faccb27ac11f3d4a1fdc098ebb6255d5612 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 3 Aug 2022 16:23:32 +0200 Subject: Website gen adjustments --- scripts/metadata.lua | 89 ++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 44 deletions(-) (limited to 'scripts/metadata.lua') 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 -- cgit v1.2.3-70-g09d2