From c20ea9f6922557db29061a5d53c067ab20c734b9 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 13 Nov 2021 18:03:55 +0100 Subject: Improved list generation, remove index template --- scripts/metadata_filter.lua | 76 +++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 34 deletions(-) (limited to 'scripts/metadata_filter.lua') diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 7039a2c..ebd69f1 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua @@ -33,30 +33,6 @@ function table_to_list(t, kv, cmp) return l end -function group_by(l, field, insert) - insert = insert or function(group, _, item) - if not group then - group = l:new({ item }) - return group - end - group:insert(item) - end - - local groups = {} - - for i = 1, #l do - local item = l[i] - local f = field(item) - - if f then - local out = insert(groups[f], f, item) - if out then groups[f] = out end - end - end - - return groups -end - function make_absolute(rel, base) return path.is_absolute(rel) and rel or path.join({ path.directory(base), rel }) end @@ -67,15 +43,28 @@ function resolve_url(site_url, ref_file, target_file) local ref_base_dir = path.directory(ref_file) local abs = target_file local rel = path.make_relative(abs, ref_base_dir, true) + local full = (abs[1] == "/" and (site_url .. abs)) or abs - return { abs = abs, rel = rel, full = (site_url .. abs) } + return { abs = abs, rel = rel, full = full } end -function resolve_layout(layout) - if layout then - layout = pandoc.utils.stringify(layout) - return { id = layout, ["is_" .. layout] = true } +function resolve_layout(depth) + local layout = "deep_categorized_list" + + if depth == "0" then + layout = "page" + elseif depth == "1" then + layout = "list" + elseif depth == "2" then + layout = "categorized_list" end + + return layout +end + +function prep_layout(layout) + layout = pandoc.utils.stringify(layout) + return { id = layout, ["is_" .. layout] = true } end function resolve_namespace(namespace) @@ -110,8 +99,10 @@ function process_pages(global, order, pages_by_id) for _, page in pairs(pages_by_id) do local p = process(global, page) - pages_all:insert(p) - if p.date then pages_date_desc:insert(p) end + if not p.unlisted then + pages_all:insert(p) + if p.date then pages_date_desc:insert(p) end + end end pages_all:sort(function(p1, p2) @@ -171,12 +162,27 @@ function titlecase(str) end) end +function find_depth(pages) + local depth = 0 + + for i = 1, #pages do + local p = pages[i] + local d = tonumber(p.depth) + if d > depth then depth = d end + end + + depth = depth + 1 + + return tostring(depth) +end + function process(global, meta) meta.namespace = resolve_namespace(meta.namespace) meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") - 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 "" + meta.url = meta.url and pandoc.utils.stringify(meta.url) + meta.url = resolve_url(global.site.url, global.file_out, meta.url or meta.file_out) + meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" + if meta.titlecase ~= false then meta.title = titlecase(meta.title) end 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 @@ -204,6 +210,8 @@ function process(global, meta) end meta.pages = process_pages(global, meta.list_order, meta.pages) + meta.depth = (meta.pages and find_depth(meta.pages.all)) or "0" + meta.layout = prep_layout(meta.layout or resolve_layout(meta.depth)) if meta.date then meta.date = format_date(meta.date) -- cgit v1.2.3-54-g00ecf