summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-06-13 08:43:35 +0200
committerVolpeon <git@volpeon.ink>2022-06-13 08:43:35 +0200
commitaf3b016717605153abf786390f9fa3d77ce402e0 (patch)
tree78382adbefd20bc652721720a1d821189b11c22f /scripts
parentUpdate (diff)
downloadvolpeon.ink-af3b016717605153abf786390f9fa3d77ce402e0.tar.gz
volpeon.ink-af3b016717605153abf786390f9fa3d77ce402e0.tar.bz2
volpeon.ink-af3b016717605153abf786390f9fa3d77ce402e0.zip
Control list flattening via metadata
Diffstat (limited to 'scripts')
-rw-r--r--scripts/metadata_filter.lua19
1 files changed, 16 insertions, 3 deletions
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua
index cb060fa..07f060c 100644
--- a/scripts/metadata_filter.lua
+++ b/scripts/metadata_filter.lua
@@ -27,6 +27,19 @@ function pandoc.List:take(n)
27 return result 27 return result
28end 28end
29 29
30function dump(o)
31 if type(o) == 'table' then
32 local s = '{ '
33 for k, v in pairs(o) do
34 if type(k) ~= 'number' then k = '"' .. k .. '"' end
35 s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
36 end
37 return s .. '} '
38 else
39 return tostring(o)
40 end
41end
42
30function page_sort(order) 43function page_sort(order)
31 return function(p1, p2) 44 return function(p1, p2)
32 if p1.position then 45 if p1.position then
@@ -241,10 +254,10 @@ function generate_list(meta)
241 return meta.pages.all 254 return meta.pages.all
242 :map(function(cat) 255 :map(function(cat)
243 local allItems = (cat.pages and cat.pages.all or pandoc.List()):flatMap(function(c) 256 local allItems = (cat.pages and cat.pages.all or pandoc.List()):flatMap(function(c)
244 if c.pages then 257 if not c.pages or not cat.list_flatten then
245 return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end)
246 else
247 return pandoc.List({ d1_page_to_list_item(cat, c) }) 258 return pandoc.List({ d1_page_to_list_item(cat, c) })
259 else
260 return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end)
248 end 261 end
249 end) 262 end)
250 allItems:sort(page_sort(cat.list_order)) 263 allItems:sort(page_sort(cat.list_order))