From 82ee57d61c1ef24f75dc2d50ddeba756114fa522 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 3 Aug 2022 21:32:51 +0200 Subject: Code reorganization --- scripts/metadata.lua | 76 +++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/scripts/metadata.lua b/scripts/metadata.lua index 7d9206f..6aa679a 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua @@ -106,24 +106,25 @@ function prep_menu(active_id, main_menu) return { items = items, active = active_item } end -function process_pages(global, build, order, pages_by_id) +function process_pages(global, build, meta) + local order = meta.list_order + local pages_all = pandoc.List() local pages_date_desc = pandoc.List() - if pages_by_id then - 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 - end - end + for _, p in pairs(meta.pages) do + process(global, build, p) - pages_all:sort(page_sort(order)) - pages_date_desc:sort(page_sort("date_desc")) + if not p.unlisted then + pages_all:insert(p) + if p.last_update then pages_date_desc:insert(p) end + end end - return { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } + pages_all:sort(page_sort(order)) + pages_date_desc:sort(page_sort("date_desc")) + + meta.pages = { all = pages_all, date_desc = pages_date_desc, by_id = meta.pages } end function find_depth(meta) @@ -162,6 +163,28 @@ function resolve_urls(global, build, meta) if meta.thumbnail then meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) end + + -- for _, p in pairs(meta.pages.by_id) do + -- resolve_urls(global, build, p) + -- end +end + +function resolve_dates(meta) + if meta.last_update then + meta.last_update = format_date(meta.last_update) + elseif #meta.pages.date_desc ~= 0 then + meta.last_update = meta.pages.date_desc[1].last_update + elseif meta.date then + meta.last_update = format_date(meta.date) + end + + if meta.date then + meta.date = format_date(meta.date) + elseif meta.last_update then + meta.date = meta.last_update + end + + meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd end function d1_page_to_list_item(meta, p) @@ -226,7 +249,7 @@ function cat_to_list_cat(cat, allItems) end function generate_list(meta) - if meta.depth < 1 then return nil end + if meta.depth < 1 then return pandoc.List() end if meta.depth == 1 then return meta.pages.all:map(function(p) return d1_page_to_list_item(meta, p) end) @@ -263,7 +286,7 @@ function generate_list(meta) end end -function process(global, build, meta) +function process_base(build, meta) meta.namespace = resolve_namespace(meta.namespace) meta.file_out = pandoc.utils.stringify(meta.file_out) meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") @@ -277,27 +300,14 @@ function process(global, build, meta) 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) - - 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)) +end - if meta.last_update then - meta.last_update = format_date(meta.last_update) - elseif #meta.pages.date_desc ~= 0 then - meta.last_update = meta.pages.date_desc[1].last_update - elseif meta.date then - meta.last_update = format_date(meta.date) - end - - if meta.date then - meta.date = format_date(meta.date) - elseif meta.last_update then - meta.date = meta.last_update - end - - meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd +function process(global, build, meta) + process_base(build, meta) + resolve_urls(global, build, meta) + process_pages(global, build, meta) + resolve_dates(meta) end function Meta(meta) -- cgit v1.2.3-70-g09d2