From 385db81296bccf0c9e4341580d96e6a868f9d7f0 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 5 Jun 2021 17:12:33 +0200 Subject: Some design fixes, page list metadata improvements --- scripts/metadata_filter.lua | 81 +++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 33 deletions(-) (limited to 'scripts') diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 895139d..3bea687 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua @@ -106,11 +106,18 @@ end function process_pages(global, pages_by_id) if not pages_by_id then return nil end - local pages_list = pandoc.List() - - for _, page in pairs(pages_by_id) do pages_list:insert(process(global, page)) end + local pages_all = pandoc.List() + local pages_asc_title = pandoc.List() + local pages_desc_date = pandoc.List() + + for _, page in pairs(pages_by_id) do + local p = process(global, page) + pages_all:insert(p) + pages_asc_title:insert(p) + if p.date then pages_desc_date:insert(p) end + end - pages_list:sort(function(p1, p2) + pages_all:sort(function(p1, p2) if p1.position then if p2.position then return tonumber(p1.position) < tonumber(p2.position) @@ -132,36 +139,40 @@ function process_pages(global, pages_by_id) end end) - local pages_by_category = pages_list:filter(function(p) return p.category ~= nil end) - pages_by_category = group_by(pages_by_category, function(p) return p.category.id end, - function(data, _, p) - if not data then - local l = pandoc.List() - l:insert(p) - return { name = pandoc.utils.stringify(p.category.name), pages = l } + pages_desc_date:sort(function(p1, p2) + if p1.position then + if p2.position then + return tonumber(p1.position) < tonumber(p2.position) else - data.pages:insert(p) + return true end - end) - pages_by_category = table_to_list(pages_by_category, false, - function(i1, i2) return i1.name < i2.name end) - - local pages_data = { all = pages_list, by_id = pages_by_id, by_category = pages_by_category } - - return pages_data -end - -function pages_last_update(all_pages) - local last_update = format_date("1990-01-01") + else + return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd + end + end) - for i = 1, #all_pages do - local page = all_pages[i] - if page.last_update and page.last_update.yyyy_mm_dd > last_update.yyyy_mm_dd then - last_update = page.last_update + pages_asc_title:sort(function(p1, p2) + if p1.position then + if p2.position then + return tonumber(p1.position) < tonumber(p2.position) + else + return true + end + elseif p2.position then + return false + else + return p1.title < p2.title end - end + end) + + local pages_data = { + all = pages_all, + desc_date = pages_desc_date, + asc_title = pages_asc_title, + by_id = pages_by_id, + } - return last_update + return pages_data end local titlecase_exceptions = pandoc.List({ @@ -208,20 +219,24 @@ function process(global, meta) meta.preview = resolve_url(global.site.url, global.file_out, meta.preview) end - if meta.date then meta.date = format_date(meta.date) 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.pages) + if meta.date then + meta.date = format_date(meta.date) + elseif meta.pages and #meta.pages.desc_date ~= 0 then + meta.date = meta.pages.desc_date[1].date + end + if meta.last_update then meta.last_update = format_date(meta.last_update) + elseif meta.pages and #meta.pages.desc_date ~= 0 then + meta.last_update = meta.pages.desc_date[1].last_update elseif meta.date then meta.last_update = meta.date - elseif meta.pages then - meta.last_update = pages_last_update(meta.pages.all) end return meta -- cgit v1.2.3-70-g09d2