From fcbb697dc92c3368089f0d1cae3ef348f77257b6 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Fri, 5 Aug 2022 06:51:52 +0200 Subject: Prune parents and subpages --- scripts/metadata.lua | 4 ++-- scripts/page.lua | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/metadata.lua b/scripts/metadata.lua index 42bf71c..5d372fc 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua @@ -84,12 +84,12 @@ function process_pages(meta) pages_all:sort(sort.page_sort(meta.list_order, meta.pages)) pages_date_desc:sort(sort.page_sort("date_desc", meta.pages)) - --local pages_random = pages_all:clone():shuffle() + local pages_random = pages_all:clone():shuffle() meta.pages = { all = pages_all, date_desc = pages_date_desc, - --random = pages_random, + random = pages_random, by_id = meta.pages } end diff --git a/scripts/page.lua b/scripts/page.lua index e18f392..4eeebb2 100644 --- a/scripts/page.lua +++ b/scripts/page.lua @@ -138,7 +138,7 @@ end function process_pages(meta) meta.pages.all = meta.pages.all:filterMap(deref_page(meta.pages.by_id)) meta.pages.date_desc = meta.pages.date_desc:filterMap(deref_page(meta.pages.by_id)) - --meta.pages.random = meta.pages.random:filterMap(deref_page(meta.pages.by_id)) + meta.pages.random = meta.pages.random:filterMap(deref_page(meta.pages.by_id)) end function resolve_urls(global, build, meta) @@ -191,6 +191,31 @@ function process(global, build, meta, dir) end end +function prune_pages(meta, n) + if n == 0 then + meta.pages = { + all = pandoc.List(), + date_desc = pandoc.List(), + random = pandoc.List(), + by_id = {} + } + else + for _, p in pairs(meta.pages.by_id) do + prune_pages(p, n - 1) + end + end +end + +function prune(meta, up, down) + prune_pages(meta, down) + + if up == 0 then + meta.parent = nil + elseif meta.parent then + prune(meta.parent, up - 1, down) + end +end + function Meta(meta) local build = {} @@ -230,7 +255,7 @@ function Meta(meta) global.menus.main = prep_menu(meta.namespace.full, global.menus.main) end - meta.parent = nil + prune(meta, 0, 2) for key, value in pairs(global) do meta[key] = value -- cgit v1.2.3-70-g09d2