From b3e7a555a21c300e34d256badfa6fa6501840756 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 27 Jul 2022 21:52:59 +0200 Subject: Better handling of drafts --- content/notebook/pages/index.md | 1 + scripts/metadata.lua | 35 ++++++++++++++--------------------- templates/feed.xml | 22 +++++++++------------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/content/notebook/pages/index.md b/content/notebook/pages/index.md index b32e28a..1c8fbc5 100644 --- a/content/notebook/pages/index.md +++ b/content/notebook/pages/index.md @@ -1,5 +1,6 @@ --- title: Pages +depth: 1 position: 1 list_read_indicators: true feed: true diff --git a/scripts/metadata.lua b/scripts/metadata.lua index 98ad9e5..9cb9970 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua @@ -162,9 +162,7 @@ function process_pages(global, order, pages_by_id) pages_date_desc:sort(page_sort("date_desc")) end - local pages_data = { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } - - return pages_data + return { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } end function find_depth(pages) @@ -240,21 +238,17 @@ function cat_to_list_cat(cat, allItems) } end -function generate_list(global, meta) +function generate_list(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) - :filter(function(p) return not p.draft or global.mode == "dev" end) + return meta.pages.all:map(function(p) return d1_page_to_list_item(meta, p) 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) - :filter(function(p) return not p.draft or global.mode == "dev" end) + local allItems = cat.pages.all:map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) return cat_to_list_cat(cat, allItems) end) @@ -264,15 +258,13 @@ function generate_list(global, meta) if meta.depth == 3 then 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) - :filter(function(p) return not p.draft or global.mode == "dev" end) + local allItems = cat.pages.all:flatMap(function(c) + if cat.list_flatten and c.depth ~= 0 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) allItems:sort(page_sort(cat.list_order)) @@ -287,6 +279,7 @@ end function process(global, meta) meta.namespace = resolve_namespace(meta.namespace) meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") + meta.unlisted = meta.unlisted or (meta.draft and global.mode ~= "dev") meta.redirect = meta.url and true 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) @@ -321,7 +314,7 @@ function process(global, meta) end meta.pages = process_pages(global, meta.list_order, meta.pages) - meta.depth = find_depth(meta.pages) + meta.depth = meta.depth and tonumber(pandoc.utils.stringify(meta.depth)) or find_depth(meta.pages) meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) if meta.last_update then @@ -338,7 +331,7 @@ function process(global, meta) meta.date = meta.last_update end - meta.list = generate_list(global, meta) + meta.list = generate_list(meta) return meta end diff --git a/templates/feed.xml b/templates/feed.xml index e6d3cae..915c000 100644 --- a/templates/feed.xml +++ b/templates/feed.xml @@ -17,24 +17,20 @@ $if(layout.is_categorized_list)$ $for(pages.date_desc)$ $for(it.pages.date_desc)$ - $if(it.draft)$$else$ - $if(it.url)$ - - - $it:feed_entry()$ - - $endif$ - $endif$ - $endfor$ - $endfor$ - $else$ - $for(pages.date_desc)$ - $if(it.draft)$$else$ $if(it.url)$ + $it:feed_entry()$ $endif$ + $endfor$ + $endfor$ + $else$ + $for(pages.date_desc)$ + $if(it.url)$ + + $it:feed_entry()$ + $endif$ $endfor$ $endif$ -- cgit v1.2.3-70-g09d2