From fd8aa54a4ce623d55219b1865e23b93b3b26e265 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 27 Jul 2022 19:10:15 +0200 Subject: Added draft feature --- Makefile | 7 +++- content/notebook/pages/i-want-to-be-a-fox.md | 6 +++ content/notebook/pages/index.md | 1 - scripts/metadata.lua | 57 ++++++++++++++++------------ templates/layouts/page.html | 6 +++ templates/partials/gallery_card.html | 7 +++- templates/partials/grid_card.html | 7 +++- templates/partials/list_card.html | 16 ++++---- 8 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 content/notebook/pages/i-want-to-be-a-fox.md diff --git a/Makefile b/Makefile index 6801970..cfc583f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ export DEPLOY_TARGET = vulpes@94.130.78.123:/srv/http/volpeon.ink/ +export MODE = prod -include Env.mk @@ -61,10 +62,11 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ -t html5 \ --wrap preserve \ --no-highlight \ + --metadata-file "$@.pages" \ --template scripts/metadata.json \ + --metadata mode="$(MODE)" \ --metadata namespace="$(NAMESPACE)" \ --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ - --metadata-file "$@.pages" \ $(PANDOC_FILTERS) \ -o "$@.meta" "$<" rm "$@.pages" @@ -76,6 +78,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ --lua-filter scripts/subpages.lua \ $(GLOBAL_METADATA) \ --metadata-file "$@.meta" \ + --metadata mode="$(MODE)" \ --metadata file_out="$@" \ $(PANDOC_FILTERS) \ -o "$@.content" "$<" @@ -99,6 +102,7 @@ out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLAT --lua-filter scripts/metadata.lua \ $(GLOBAL_METADATA) \ --metadata-file .cache/assets.json \ + --metadata mode="$(MODE)" \ --metadata-file "$(filter .cache/meta/%.json,$^)" \ --metadata file_out="$@" \ $(PANDOC_FILTERS) \ @@ -117,6 +121,7 @@ out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml --lua-filter scripts/metadata.lua \ $(GLOBAL_METADATA) \ --metadata-file "$(filter .cache/meta/%.json,$^)" \ + --metadata mode="$(MODE)" \ --metadata file_out="$@" \ $(PANDOC_FILTERS) \ -o "$@" "$<" diff --git a/content/notebook/pages/i-want-to-be-a-fox.md b/content/notebook/pages/i-want-to-be-a-fox.md new file mode 100644 index 0000000..f43cac3 --- /dev/null +++ b/content/notebook/pages/i-want-to-be-a-fox.md @@ -0,0 +1,6 @@ +--- +schema_type: DigitalDocument +title: I Want To Be a Fox +date: 2022-08-27 +draft: true +--- diff --git a/content/notebook/pages/index.md b/content/notebook/pages/index.md index 510b20b..b32e28a 100644 --- a/content/notebook/pages/index.md +++ b/content/notebook/pages/index.md @@ -3,5 +3,4 @@ title: Pages position: 1 list_read_indicators: true feed: true -unlisted: true --- 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 diff --git a/templates/layouts/page.html b/templates/layouts/page.html index c1bd051..b93f45f 100644 --- a/templates/layouts/page.html +++ b/templates/layouts/page.html @@ -12,6 +12,12 @@ $endif$ + $if(draft)$ + + Draft + + $endif$ +

$title$

diff --git a/templates/partials/gallery_card.html b/templates/partials/gallery_card.html index 3020c2d..e319fa4 100644 --- a/templates/partials/gallery_card.html +++ b/templates/partials/gallery_card.html @@ -30,13 +30,16 @@ $if(it.thumbnail)$ $endif$
- $if(it.subtitle)$ + $if(it.draft)$ + $it.title$ +
Draft
+ $elseif(it.subtitle)$ $it.title$ $it.subtitle$ $elseif(it.category)$ $it.category$ $it.title$ - $elseif(it.last_update)$ + $elseif(it.show_date)$
+ $if(it.draft)$ +
Draft
+ $elseif(it.subtitle)$ + $it.subtitle$ $elseif(it.category)$ - - $it.category$ - - $elseif(it.last_update)$ + $it.category$ + $elseif(it.show_date)$