From 8a3b78c8e07dea97d8b51d1ec6ff2f5ff814f95a Mon Sep 17 00:00:00 2001 From: Volpeon Date: Fri, 29 Jul 2022 07:59:41 +0200 Subject: Better depth calculation --- scripts/metadata.lua | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/metadata.lua b/scripts/metadata.lua index a32ee29..27854b9 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua @@ -165,16 +165,26 @@ function process_pages(global, order, pages_by_id) return { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } end -function find_depth(pages) +function find_depth(meta) + if meta.depth then + meta.depth = tonumber(meta.depth) + end + local depth = 0 - for i = 1, #pages.all do - local p = pages.all[i] - local d = p.depth + 1 - if d > depth then depth = d end + 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 + end end - return depth + meta.depth = depth + + return meta end function d1_page_to_list_item(meta, p) @@ -314,7 +324,6 @@ function process(global, meta) end meta.pages = process_pages(global, meta.list_order, meta.pages) - meta.depth = meta.depth and tonumber(pandoc.utils.stringify(meta.depth)) or find_depth(meta.pages) meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) if meta.last_update then @@ -339,5 +348,6 @@ end function Meta(meta) meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") + find_depth(meta) return process(meta, meta) end -- cgit v1.2.3-70-g09d2