From 9763ea03164f983d77051a84609dcae80885b1c0 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Fri, 12 Nov 2021 20:39:46 +0100 Subject: Improved page --- scripts/metadata_filter.lua | 57 +++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 38 deletions(-) (limited to 'scripts') diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index daad940..7039a2c 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua @@ -102,18 +102,16 @@ function prep_menu(active_id, main_menu) return { items = items, active = active_item } end -function process_pages(global, pages_by_id) +function process_pages(global, order, pages_by_id) if not pages_by_id then return nil end local pages_all = pandoc.List() - local pages_asc_title = pandoc.List() - local pages_desc_date = pandoc.List() + local pages_date_desc = 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 + if p.date then pages_date_desc:insert(p) end end pages_all:sort(function(p1, p2) @@ -125,20 +123,22 @@ function process_pages(global, pages_by_id) end elseif p2.position then return false - elseif p1.date then - if p2.date then - return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd + elseif order == "date_desc" then + if p1.date then + if p2.date then + return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd + else + return true + end else - return true + return false end - elseif p2.date then - return false else return p1.title < p2.title end end) - pages_desc_date:sort(function(p1, p2) + pages_date_desc:sort(function(p1, p2) if p1.position then if p2.position then return tonumber(p1.position) < tonumber(p2.position) @@ -150,26 +150,7 @@ function process_pages(global, pages_by_id) end end) - 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) - - local pages_data = { - all = pages_all, - desc_date = pages_desc_date, - asc_title = pages_asc_title, - by_id = pages_by_id, - } + local pages_data = { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } return pages_data end @@ -196,7 +177,7 @@ function process(global, meta) meta.layout = resolve_layout(meta.layout) meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) meta.title = (meta.title and titlecase(pandoc.utils.stringify(meta.title))) or "" - + if meta.list_order then meta.list_order = pandoc.utils.stringify(meta.list_order) end if meta.position then meta.position = pandoc.utils.stringify(meta.position) end if meta.create_feed then @@ -222,18 +203,18 @@ function process(global, meta) meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) end - meta.pages = process_pages(global, meta.pages) + meta.pages = process_pages(global, meta.list_order, 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 + elseif meta.pages and #meta.pages.date_desc ~= 0 then + meta.date = meta.pages.date_desc[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.pages and #meta.pages.date_desc ~= 0 then + meta.last_update = meta.pages.date_desc[1].last_update elseif meta.date then meta.last_update = meta.date end -- cgit v1.2.3-70-g09d2