From ac027192285ad741b3ac1b837e1c363beb8f3791 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 14 Nov 2021 09:28:25 +0100 Subject: Generate special list metadata --- content/profiles/bandcamp/index.md | 6 +- content/profiles/email/index.md | 6 +- content/profiles/fediverse/index.md | 6 +- content/profiles/git/index.md | 5 ++ content/profiles/git/main.md | 5 ++ content/profiles/github/index.md | 5 -- content/profiles/github/main.md | 5 -- content/profiles/index.md | 2 +- content/projects/emojis/index.md | 5 +- content/projects/index.md | 2 +- scripts/metadata_filter.lua | 96 +++++++++++++++++++++++++--- templates/base.html | 4 +- templates/layouts/categorized_list.html | 86 ++++--------------------- templates/layouts/deep_categorized_list.html | 54 ---------------- templates/layouts/list.html | 64 +------------------ templates/partials/grid_card.html | 33 ++++++++++ templates/partials/list_card.html | 34 ++++++++++ 17 files changed, 194 insertions(+), 224 deletions(-) create mode 100644 content/profiles/git/index.md create mode 100644 content/profiles/git/main.md delete mode 100644 content/profiles/github/index.md delete mode 100644 content/profiles/github/main.md delete mode 100644 templates/layouts/deep_categorized_list.html create mode 100644 templates/partials/grid_card.html create mode 100644 templates/partials/list_card.html diff --git a/content/profiles/bandcamp/index.md b/content/profiles/bandcamp/index.md index 34f3c88..0a47469 100644 --- a/content/profiles/bandcamp/index.md +++ b/content/profiles/bandcamp/index.md @@ -1,5 +1,5 @@ --- -title: Bandcamp -icon: parallelogram -list_icon: icon-arrow-up-right +title: Bandcamp +icon: parallelogram +list_post_icon: icon-arrow-up-right --- diff --git a/content/profiles/email/index.md b/content/profiles/email/index.md index e305535..6eef738 100644 --- a/content/profiles/email/index.md +++ b/content/profiles/email/index.md @@ -1,5 +1,5 @@ --- -title: E-Mail -icon: envelope -list_icon: icon-arrow-up-right +title: E-Mail +icon: envelope +list_post_icon: icon-arrow-up-right --- diff --git a/content/profiles/fediverse/index.md b/content/profiles/fediverse/index.md index ed35dc1..56eb848 100644 --- a/content/profiles/fediverse/index.md +++ b/content/profiles/fediverse/index.md @@ -1,5 +1,5 @@ --- -title: Fediverse -icon: graph -list_icon: icon-arrow-up-right +title: Fediverse +icon: graph +list_post_icon: icon-arrow-up-right --- diff --git a/content/profiles/git/index.md b/content/profiles/git/index.md new file mode 100644 index 0000000..0d747a6 --- /dev/null +++ b/content/profiles/git/index.md @@ -0,0 +1,5 @@ +--- +title: Git +icon: git-branch +list_post_icon: icon-arrow-up-right +--- diff --git a/content/profiles/git/main.md b/content/profiles/git/main.md new file mode 100644 index 0000000..fb25680 --- /dev/null +++ b/content/profiles/git/main.md @@ -0,0 +1,5 @@ +--- +title: "git.vulpes.one" +titlecase: false +url: "https://git.vulpes.one/" +--- diff --git a/content/profiles/github/index.md b/content/profiles/github/index.md deleted file mode 100644 index d4f011d..0000000 --- a/content/profiles/github/index.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Git -icon: git-branch -list_icon: icon-arrow-up-right ---- diff --git a/content/profiles/github/main.md b/content/profiles/github/main.md deleted file mode 100644 index fb25680..0000000 --- a/content/profiles/github/main.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: "git.vulpes.one" -titlecase: false -url: "https://git.vulpes.one/" ---- diff --git a/content/profiles/index.md b/content/profiles/index.md index 1041807..6514367 100644 --- a/content/profiles/index.md +++ b/content/profiles/index.md @@ -1,5 +1,5 @@ --- title: Profiles +position: 1 list_grid: true -list_icon: icon-arrow-up-right --- diff --git a/content/projects/emojis/index.md b/content/projects/emojis/index.md index cbffe1b..58ad85b 100644 --- a/content/projects/emojis/index.md +++ b/content/projects/emojis/index.md @@ -1,4 +1,5 @@ --- -title: Emojis -icon: smile +title: Emojis +icon: smile +list_post_icon: icon-arrow-right --- diff --git a/content/projects/index.md b/content/projects/index.md index c79f803..546ae46 100644 --- a/content/projects/index.md +++ b/content/projects/index.md @@ -1,5 +1,5 @@ --- title: Projects +position: 2 list_grid: true -list_icon: icon-arrow-right --- diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index ebd69f1..b16d472 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua @@ -1,5 +1,14 @@ local path = require 'pandoc.path' +function pandoc.List:flatMap(fn) + local mapped = self:map(fn) + local result = pandoc.List() + + for i = 1, #mapped do result:extend(mapped[i]) end + + return result +end + function format_date(date) if not date then return date end @@ -49,14 +58,12 @@ function resolve_url(site_url, ref_file, target_file) end function resolve_layout(depth) - local layout = "deep_categorized_list" + local layout = "categorized_list" if depth == "0" then layout = "page" elseif depth == "1" then layout = "list" - elseif depth == "2" then - layout = "categorized_list" end return layout @@ -91,14 +98,14 @@ function prep_menu(active_id, main_menu) return { items = items, active = active_item } end -function process_pages(global, order, pages_by_id) +function process_pages(global, parent, order, pages_by_id) if not pages_by_id then return nil end local pages_all = pandoc.List() local pages_date_desc = pandoc.List() for _, page in pairs(pages_by_id) do - local p = process(global, page) + local p = process(global, parent, page) if not p.unlisted then pages_all:insert(p) if p.date then pages_date_desc:insert(p) end @@ -176,7 +183,77 @@ function find_depth(pages) return tostring(depth) end -function process(global, meta) +function generate_list(meta) + if meta.depth == "1" then + return meta.pages.all:map(function(p) + return { + title = p.title, + subtitle = p.subtitle, + date = p.date, + url = p.url, + icon = p.icon or meta.icon, + post_icon = meta.list_post_icon, + indicator = meta.list_read_indicators, + } + end) + elseif meta.depth == "2" then + return meta.pages.all:map(function(cat) + return { + title = cat.title, + content = pandoc.utils.stringify(cat.content), + url = cat.url, + grid = cat.list_grid, + items = cat.pages.all:map(function(p) + return { + title = p.title, + subtitle = p.subtitle, + date = p.date, + url = p.url, + icon = p.icon or cat.icon, + post_icon = cat.list_post_icon or meta.list_post_icon, + indicator = cat.list_read_indicators, + } + end), + } + end) + elseif meta.depth == "3" then + return meta.pages.all:map(function(cat) + return { + title = cat.title, + content = pandoc.utils.stringify(cat.content), + url = cat.url, + grid = cat.list_grid, + items = cat.pages.all:flatMap(function(c) + if c.pages then + return c.pages.all:map(function(p) + return { + title = p.title, + subtitle = p.subtitle or c.title, + url = p.url, + icon = p.icon or c.icon, + post_icon = c.list_post_icon or cat.list_post_icon, + indicator = c.list_read_indicators, + } + end) + else + local l = pandoc.List() + l:insert({ + title = c.title, + subtitle = c.subtitle, + url = c.url, + icon = c.icon or meta.icon, + post_icon = meta.list_post_icon, + indicator = meta.list_read_indicators, + }) + return l + end + end), + } + end) + end +end + +function process(global, parent, meta) meta.namespace = resolve_namespace(meta.namespace) meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") meta.url = meta.url and pandoc.utils.stringify(meta.url) @@ -209,7 +286,8 @@ function process(global, meta) meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) end - meta.pages = process_pages(global, meta.list_order, meta.pages) + meta.pages = + process_pages(global, { parent = parent, meta = meta }, 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)) @@ -227,11 +305,13 @@ function process(global, meta) meta.last_update = meta.date end + meta.list = generate_list(meta) + return meta end function Meta(meta) meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") - return process(meta, meta) + return process(meta, nil, meta) end diff --git a/templates/base.html b/templates/base.html index ede7941..eb088c4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -63,9 +63,7 @@
- $if(layout.is_deep_categorized_list)$ -${layouts/deep_categorized_list()} - $elseif(layout.is_categorized_list)$ + $if(layout.is_categorized_list)$ ${layouts/categorized_list()} $elseif(layout.is_list)$ ${layouts/list()} diff --git a/templates/layouts/categorized_list.html b/templates/layouts/categorized_list.html index ad510ae..aea8863 100644 --- a/templates/layouts/categorized_list.html +++ b/templates/layouts/categorized_list.html @@ -6,80 +6,18 @@ $body$ diff --git a/templates/layouts/deep_categorized_list.html b/templates/layouts/deep_categorized_list.html deleted file mode 100644 index eec16c9..0000000 --- a/templates/layouts/deep_categorized_list.html +++ /dev/null @@ -1,54 +0,0 @@ -
- - - -
- - diff --git a/templates/layouts/list.html b/templates/layouts/list.html index b4647a1..7a9d573 100644 --- a/templates/layouts/list.html +++ b/templates/layouts/list.html @@ -8,71 +8,11 @@ $body$ diff --git a/templates/partials/grid_card.html b/templates/partials/grid_card.html new file mode 100644 index 0000000..25c2271 --- /dev/null +++ b/templates/partials/grid_card.html @@ -0,0 +1,33 @@ + + $if(it.indicator)$ +
+ $endif$ + $if(it.icon)$ + + + + $endif$ +
+ $if(it.subtitle)$ + $it.subtitle$ + $it.title$ + $elseif(it.date)$ + + $it.title$ + $else$ + $it.title$ + $endif$ +
+ $if(it.post_icon)$ + + + + $endif$ +
diff --git a/templates/partials/list_card.html b/templates/partials/list_card.html new file mode 100644 index 0000000..644e0d3 --- /dev/null +++ b/templates/partials/list_card.html @@ -0,0 +1,34 @@ + + $if(it.indicator)$ +
+ $endif$ + $if(it.icon)$ + + + + $endif$ +
+ $it.title$ +
+ $if(it.subtitle)$ +
+ + $it.subtitle$ + +
+ $elseif(it.date)$ + + $endif$ + $if(it.post_icon)$ + + + + $endif$ +
-- cgit v1.2.3-70-g09d2