From 4c9eb23ac5c609c5f880b98be9e9e3c9c905fe85 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 14 Nov 2021 12:34:03 +0100 Subject: List generation: Handle empty subpages list better --- scripts/metadata_filter.lua | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 4014db4..0ff7429 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua @@ -184,6 +184,8 @@ function find_depth(pages) end function generate_list(meta) + if not meta.pages then return nil end + if meta.depth == "1" then return meta.pages.all:map(function(p) return { @@ -203,7 +205,7 @@ function generate_list(meta) content = cat.content, url = cat.url, grid = cat.list_grid, - items = cat.pages.all:map(function(p) + items = ((cat.pages and cat.pages.all) or pandoc.List()):map(function(p) return { title = p.title, subtitle = p.subtitle, @@ -215,13 +217,15 @@ function generate_list(meta) } end), } - end) + end):filter(function(cat) return #cat.items ~= 0 end) elseif meta.depth == "3" then return meta.pages.all:map(function(cat) - local items = pandoc.List() - - if cat.pages then - items = cat.pages.all:flatMap(function(c) + return { + title = cat.title, + content = cat.content, + url = cat.url, + grid = cat.list_grid, + items = (cat.pages and cat.pages.all or pandoc.List()):flatMap(function(c) if c.pages then return c.pages.all:map(function(p) return { @@ -246,17 +250,9 @@ function generate_list(meta) }) return l end - end) - end - - return { - title = cat.title, - content = cat.content, - url = cat.url, - grid = cat.list_grid, - items = items, + end), } - end) + end):filter(function(cat) return #cat.items ~= 0 end) end end -- cgit v1.2.3-70-g09d2