From fd8aa54a4ce623d55219b1865e23b93b3b26e265 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 27 Jul 2022 19:10:15 +0200 Subject: Added draft feature --- scripts/metadata.lua | 57 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'scripts') diff --git a/scripts/metadata.lua b/scripts/metadata.lua index 872034c..98ad9e5 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua @@ -170,14 +170,10 @@ end function find_depth(pages) local depth = 0 - if #pages.all ~= 0 then - for i = 1, #pages.all do - local p = pages.all[i] - local d = tonumber(p.depth) - if d > depth then depth = d end - end - - depth = depth + 1 + for i = 1, #pages.all do + local p = pages.all[i] + local d = tonumber(p.depth) + 1 + if d > depth then depth = d end end return depth @@ -187,9 +183,11 @@ function d1_page_to_list_item(meta, p) return { title = p.title, subtitle = p.subtitle, - date = meta.list_order == "date_desc" and p.date, - last_update = meta.list_order == "date_desc" and p.last_update, + date = p.date, + last_update = p.last_update, + show_date = meta.list_order == "date_desc", schema_type = p.schema_type, + draft = p.draft, position = p.position, url = p.url, rel = p.rel, @@ -206,9 +204,11 @@ function d2_page_to_list_item(meta, cat, p, set_cat_title) title = p.title, subtitle = p.subtitle, category = set_cat_title and cat.title, - date = cat.list_order == "date_desc" and p.date, - last_update = cat.list_order == "date_desc" and p.last_update, + date = p.date, + last_update = p.last_update, + show_date = cat.list_order == "date_desc", schema_type = p.schema_type, + draft = p.draft, position = p.position, url = p.url, rel = p.rel, @@ -240,17 +240,21 @@ function cat_to_list_cat(cat, allItems) } end -function generate_list(meta) +function generate_list(global, meta) if meta.depth < 1 then return nil end if meta.depth == 1 then - return meta.pages.all:map(function(p) return d1_page_to_list_item(meta, p) end) + return meta.pages.all + :map(function(p) return d1_page_to_list_item(meta, p) end) + :filter(function(p) return not p.draft or global.mode == "dev" end) end if meta.depth == 2 then return meta.pages.all :map(function(cat) - local allItems = cat.pages.all:map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) + local allItems = cat.pages.all + :map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) + :filter(function(p) return not p.draft or global.mode == "dev" end) return cat_to_list_cat(cat, allItems) end) @@ -258,20 +262,25 @@ function generate_list(meta) end if meta.depth == 3 then - return meta.pages.all + local list = meta.pages.all :map(function(cat) - local allItems = cat.pages.all:flatMap(function(c) - if #c.pages.all ~= 0 and cat.list_flatten then - return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end) - else - return pandoc.List({ d1_page_to_list_item(cat, c) }) - end - end) + local allItems = cat.pages.all + :flatMap(function(c) + if #c.pages.all ~= 0 and cat.list_flatten then + return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end) + else + return pandoc.List({ d1_page_to_list_item(cat, c) }) + end + end) + :filter(function(p) return not p.draft or global.mode == "dev" end) + allItems:sort(page_sort(cat.list_order)) return cat_to_list_cat(cat, allItems) end) :filter(function(cat) return #cat.items ~= 0 end) + + return list end end @@ -329,7 +338,7 @@ function process(global, meta) meta.date = meta.last_update end - meta.list = generate_list(meta) + meta.list = generate_list(global, meta) return meta end -- cgit v1.2.3-54-g00ecf