From 61e141f8c1e72c530683cfaca0c1b17077d2385d Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 10 Jul 2022 10:11:46 +0200 Subject: Update --- Makefile | 14 +- content/notebook/fediverse/foxes-and-me.md | 24 -- content/notebook/fediverse/i-want-to-be-a-fox.md | 24 ++ .../fediverse/in-depth-image-descriptions.md | 2 +- content/notebook/fediverse/index.md | 1 + content/notebook/index.md | 2 +- scripts/metadata.json | 1 + scripts/metadata.lua | 342 +++++++++++++++++++++ scripts/metadata_filter.lua | 342 --------------------- scripts/metadata_tpl.json | 1 - 10 files changed, 377 insertions(+), 376 deletions(-) delete mode 100644 content/notebook/fediverse/foxes-and-me.md create mode 100644 content/notebook/fediverse/i-want-to-be-a-fox.md create mode 100755 scripts/metadata.json create mode 100644 scripts/metadata.lua delete mode 100644 scripts/metadata_filter.lua delete mode 100755 scripts/metadata_tpl.json diff --git a/Makefile b/Makefile index 2517b7d..dcf5414 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) -.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) filters/*.lua scripts/subpages.lua scripts/subpages.jq scripts/metadata_tpl.json | .cache/meta +.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) filters/*.lua scripts/subpages.lua scripts/subpages.jq scripts/metadata.json | .cache/meta $(info [META] $< -> $@) mkdir -p $(@D) @@ -60,7 +60,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ -t html5 \ --wrap preserve \ --no-highlight \ - --template scripts/metadata_tpl.json \ + --template scripts/metadata.json \ --metadata namespace="$(NAMESPACE)" \ --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ --metadata-file "$@.pages" \ @@ -71,7 +71,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ -f markdown-citations-implicit_figures \ -t html5 \ --wrap preserve \ - --lua-filter scripts/metadata_filter.lua \ + --lua-filter scripts/metadata.lua \ --lua-filter scripts/subpages.lua \ $(GLOBAL_METADATA) \ --metadata-file "$@.meta" \ @@ -85,7 +85,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ .cache/assets.json: $(ASSET_FILES) | .cache sha256sum $^ | sed -r 's/([0-9a-f]+) +out\/(.*)/{ "\2": "\/\2?\1" }/' | jq '{ assets: [inputs] | add | with_entries( .key |= gsub( "\\."; "_") ) }' > "$@" -out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua | out +out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata.lua | out $(info [MARK] $< -> $@) mkdir -p $(@D) @@ -95,7 +95,7 @@ out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLAT --wrap preserve \ --no-highlight \ --template templates/base.html \ - --lua-filter scripts/metadata_filter.lua \ + --lua-filter scripts/metadata.lua \ $(GLOBAL_METADATA) \ --metadata-file .cache/assets.json \ --metadata-file "$(filter .cache/meta/%.json,$^)" \ @@ -103,7 +103,7 @@ out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLAT $(PANDOC_FILTERS) \ -o "$@" "$<" -out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua | out +out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata.lua | out $(info [FEED] $< -> $@) mkdir -p $(@D) @@ -113,7 +113,7 @@ out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml --wrap preserve \ --no-highlight \ --template templates/feed.xml \ - --lua-filter scripts/metadata_filter.lua \ + --lua-filter scripts/metadata.lua \ $(GLOBAL_METADATA) \ --metadata-file "$(filter .cache/meta/%.json,$^)" \ --metadata file_out="$@" \ diff --git a/content/notebook/fediverse/foxes-and-me.md b/content/notebook/fediverse/foxes-and-me.md deleted file mode 100644 index b938a3a..0000000 --- a/content/notebook/fediverse/foxes-and-me.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -schema_type: DigitalDocument -title: Foxes and me -date: 2022-07-09 - -references: - - label: Original Question - url: https://brotka.st/notice/ALFjUBS9tkCWKyprMm - - label: Original Reply - url: https://mk.vulpes.one/notes/92gm6ipdtp ---- - -::: alert -@kaia@brotka.st asked: "maybe not something you want to answer at all or publicly, but I'd be curious whether you genuinely long to be a dragon or a fox, its intensity, the motivation and background" -::: - -I don't mind replying in public. It's not like I'm trying to keep this a secret, I just rarely talk about it because I usually have nothing to say on this matter. - -So yeah, I do genuinely wish to be a fox. I don't know the source of this desire, I've just always felt more comfortable with the idea of being an animal than a human. Some of my earliest memories are about me imagining myself as a bird and focusing on the sensation of having such a different body. -It's been a constant throughout my life and I can hardly express how much I long for it to become reality. It doesn't matter that I'm completely aware of all the drawbacks and consequences, if I was given the chance I would take it in a heartbeat. - -Obviously, that will never happen, though. I accepted it because what other choice do I have, but I'd be lying if I said that it wasn't eating away at me at times. I found two things that help me handle my feelings: The first one is creating art. The second one is my online identity which lets me live out myself genuinely, unlike my "real" name and my "real" face. Here I'm not strictly limited to my body and I'm truly thankful that this possibility exists. - -As for the recent dragon stuff, I thought about what this character means to me. I identify with it because it's an expression of my creativity and taste, but it hasn't taken over the role of foxes. diff --git a/content/notebook/fediverse/i-want-to-be-a-fox.md b/content/notebook/fediverse/i-want-to-be-a-fox.md new file mode 100644 index 0000000..e562922 --- /dev/null +++ b/content/notebook/fediverse/i-want-to-be-a-fox.md @@ -0,0 +1,24 @@ +--- +schema_type: DigitalDocument +title: I Want To Be a Fox +date: 2022-07-09 + +references: + - label: Original Question + url: https://brotka.st/notice/ALFjUBS9tkCWKyprMm + - label: Original Reply + url: https://mk.vulpes.one/notes/92gm6ipdtp +--- + +::: alert +@kaia@brotka.st asked: "maybe not something you want to answer at all or publicly, but I'd be curious whether you genuinely long to be a dragon or a fox, its intensity, the motivation and background" +::: + +I don't mind replying in public. It's not like I'm trying to keep this a secret, I just rarely talk about it because I usually have nothing to say on this matter. + +So yeah, I do genuinely wish to be a fox. I don't know the source of this desire, I've just always felt more comfortable with the idea of being an animal than a human. Some of my earliest memories are about me imagining myself as a bird and focusing on the sensation of having such a different body. +It's been a constant throughout my life and I can hardly express how much I long for it to become reality. It doesn't matter that I'm completely aware of all the drawbacks and consequences, if I was given the chance I would take it in a heartbeat. + +Obviously, that will never happen, though. I accepted it because what other choice do I have, but I'd be lying if I said that it wasn't eating away at me at times. I found two things that help me handle my feelings: The first one is creating art. The second one is my online identity which lets me live out myself genuinely, unlike my "real" name and my "real" face. Here I'm not strictly limited to my body and I'm truly thankful that this possibility exists. + +As for the recent dragon stuff, I thought about what this character means to me. I identify with it because it's an expression of my creativity and taste, but it hasn't taken over the role of foxes. diff --git a/content/notebook/fediverse/in-depth-image-descriptions.md b/content/notebook/fediverse/in-depth-image-descriptions.md index 8af09ff..3143a36 100644 --- a/content/notebook/fediverse/in-depth-image-descriptions.md +++ b/content/notebook/fediverse/in-depth-image-descriptions.md @@ -1,6 +1,6 @@ --- schema_type: DigitalDocument -title: Detailed image descriptions aren't always helpful +title: Detailed Image Descriptions Aren't Always Helpful date: 2022-05-05 references: diff --git a/content/notebook/fediverse/index.md b/content/notebook/fediverse/index.md index c628a37..0c5b5f3 100644 --- a/content/notebook/fediverse/index.md +++ b/content/notebook/fediverse/index.md @@ -1,6 +1,7 @@ --- title: Fediverse position: 2 +list_order: date_desc list_read_indicators: true feed: true --- diff --git a/content/notebook/index.md b/content/notebook/index.md index 17283b0..524bebb 100644 --- a/content/notebook/index.md +++ b/content/notebook/index.md @@ -7,4 +7,4 @@ list_limit: 4 feed: true --- -Essays, notes, blogs, thoughts... all kinds of textual content. +Essays, notes, mini blogs, thoughts... all kinds of textual content. diff --git a/scripts/metadata.json b/scripts/metadata.json new file mode 100755 index 0000000..fb36f0f --- /dev/null +++ b/scripts/metadata.json @@ -0,0 +1 @@ +$meta-json$ diff --git a/scripts/metadata.lua b/scripts/metadata.lua new file mode 100644 index 0000000..8f32bd4 --- /dev/null +++ b/scripts/metadata.lua @@ -0,0 +1,342 @@ +local path = require 'pandoc.path' + +function pandoc.List:flatten() + local result = pandoc.List() + + for i = 1, #self do result:extend(self[i]) end + + return result +end + +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 pandoc.List:take(n) + if n >= #self then return self end + + local result = pandoc.List() + + for i = 1, n do result:insert(self[i]) end + + return result +end + +function dump(o) + if type(o) == 'table' then + local s = '{ ' + for k, v in pairs(o) do + if type(k) ~= 'number' then k = '"' .. k .. '"' end + s = s .. '[' .. k .. '] = ' .. dump(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + +function page_sort(order) + return function(p1, p2) + if p1.position then + if p2.position then + return tonumber(p1.position) < tonumber(p2.position) + else + return true + end + elseif p2.position then + return false + elseif order == "date_desc" then + if p1.last_update then + if p2.last_update then + return p1.last_update.yyyy_mm_dd > p2.last_update.yyyy_mm_dd + else + return true + end + else + return false + end + else + return p1.title:upper() < p2.title:upper() + end + end +end + +function slug(str) + return str:lower():gsub("[^ a-z]", ""):gsub("[ ]+", "-") +end + +function format_date(date) + if not date then return date end + + date = pandoc.utils.normalize_date(pandoc.utils.stringify(date)) + local year, month, day = date:match("(%d%d%d%d)-(%d%d)-(%d%d)") + if not year then return nil end + + local time = os.time({ year = tonumber(year), month = tonumber(month), day = tonumber(day) }) + return { + yyyy_mm_dd = os.date("%F", time), + yyyy = os.date("%Y", time), + mm = os.date("%m", time), + dd = os.date("%d", time), + rfc3339 = os.date("%FT%T+00:00", time), + long = os.date("%B %d, %Y", time), + short = os.date("%b %d, %Y", time), + } +end + +function make_absolute(rel, base) + return path.is_absolute(rel) and rel or path.join({ path.directory(base), rel }) +end + +function resolve_url(site_url, ref_file, target_file) + target_file = target_file:gsub("/index%.html$", "/") + + 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:sub(1, 1) == "/" and (site_url .. abs)) or abs + + return { abs = abs, rel = rel, full = full } +end + +function resolve_layout(depth) + local layout = "categorized_list" + + if depth == 0 then + layout = "page" + elseif depth == 1 then + layout = "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) + namespace = pandoc.utils.stringify(namespace) + + local root = "index" + if namespace ~= "" then root = namespace:gsub("^/([^/]*).*$", "%1") end + + return { root = { id = root, ["is_" .. root] = true }, full = namespace } +end + +function prep_menu(active_id, main_menu) + local active_item = nil + local items = pandoc.List() + + for i = 1, #main_menu do + local item = main_menu[i] + local active = pandoc.utils.stringify(item.id) == active_id + item.active = active + if active then active_item = item end + if not item.hidden or item.active then items:insert(item) end + end + + return { items = items, active = active_item } +end + +function process_pages(global, 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) + if not p.unlisted then + pages_all:insert(p) + if p.last_update then pages_date_desc:insert(p) end + end + end + + pages_all:sort(page_sort(order)) + pages_date_desc:sort(page_sort("date_desc")) + + local pages_data = { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } + + return pages_data +end + +function find_depth(pages) + local depth = 0 + + if pages 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 + end + + return depth +end + +function d1_page_to_list_item(meta, p) + return { + title = p.title, + subtitle = p.subtitle, + date = p.date, + last_update = p.last_update, + schema_type = p.schema_type, + position = p.position, + url = p.url, + rel = p.rel, + slug = p.slug, + thumbnail = p.thumbnail, + icon = p.icon or meta.icon, + post_icon = p.post_icon or meta.list_post_icon, + indicator = meta.list_read_indicators, + } +end + +function d2_page_to_list_item(meta, cat, p, set_cat_title) + return { + title = p.title, + subtitle = p.subtitle, + category = set_cat_title and cat.title, + date = p.date, + last_update = p.last_update, + schema_type = p.schema_type, + position = p.position, + url = p.url, + rel = p.rel, + slug = p.slug, + thumbnail = p.thumbnail, + icon = p.icon or cat.icon, + post_icon = p.post_icon or cat.list_post_icon or meta.list_post_icon, + indicator = cat.list_read_indicators, + } +end + +function cat_to_list_cat(cat, allItems) + local limit = cat.list_limit or 9999 + local items = allItems:take(limit) + local omitted = #allItems - #items + + return { + title = cat.title, + description = (cat.description and pandoc.MetaBlocks(pandoc.Para(cat.description))) or + (not cat.no_description and cat.content), + last_update = cat.last_update, + schema_type = cat.schema_type, + url = cat.url, + slug = cat.slug, + layout = cat.list_layout, + items = items, + total = tostring(#allItems), + omitted = omitted ~= 0 and tostring(omitted), + } +end + +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) + end + + if meta.depth == 2 then + return meta.pages.all + :map(function(cat) + local allItems = ((cat.pages and cat.pages.all) or pandoc.List()) + :map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) + + return cat_to_list_cat(cat, allItems) + end) + :filter(function(cat) return #cat.items ~= 0 end) + end + + if meta.depth == 3 then + return meta.pages.all + :map(function(cat) + local allItems = (cat.pages and cat.pages.all or pandoc.List()):flatMap(function(c) + if not c.pages or not cat.list_flatten then + return pandoc.List({ d1_page_to_list_item(cat, c) }) + else + return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end) + end + end) + allItems:sort(page_sort(cat.list_order)) + + return cat_to_list_cat(cat, allItems) + end) + :filter(function(cat) return #cat.items ~= 0 end) + end +end + +function process(global, meta) + meta.namespace = resolve_namespace(meta.namespace) + meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") + 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) + meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" + meta.slug = slug(meta.title) + meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork" + if meta.list_order then meta.list_order = pandoc.utils.stringify(meta.list_order) end + meta.list_layout = meta.list_layout and prep_layout(meta.list_layout) + if meta.list_limit then meta.list_limit = tonumber(pandoc.utils.stringify(meta.list_limit)) end + if meta.position then meta.position = pandoc.utils.stringify(meta.position) end + + if meta.feed then + if meta.file_out:match(".html$") then + meta.feed = { + url = resolve_url(global.site.url, global.file_out, meta.file_out:gsub(".html$", ".xml")), + } + else + meta.page = { + url = resolve_url(global.site.url, global.file_out, meta.file_out:gsub(".xml$", ".html")), + } + end + end + + if meta.thumbnail then + meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), + meta.file_out) + meta.thumbnail = resolve_url(global.site.url, global.file_out, meta.thumbnail) + end + + if meta.menus and meta.menus.main then + meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) + end + + meta.pages = process_pages(global, meta.list_order, meta.pages) + meta.depth = find_depth(meta.pages) + meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) + + if meta.date then + meta.date = format_date(meta.date) + elseif meta.pages and #meta.pages.date_desc ~= 0 then + meta.date = meta.pages.date_desc[1].date + end + + if meta.last_update then + meta.last_update = format_date(meta.last_update) + elseif meta.pages and #meta.pages.date_desc ~= 0 then + meta.last_update = meta.pages.date_desc[1].last_update + elseif meta.date then + 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) +end diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua deleted file mode 100644 index 8f32bd4..0000000 --- a/scripts/metadata_filter.lua +++ /dev/null @@ -1,342 +0,0 @@ -local path = require 'pandoc.path' - -function pandoc.List:flatten() - local result = pandoc.List() - - for i = 1, #self do result:extend(self[i]) end - - return result -end - -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 pandoc.List:take(n) - if n >= #self then return self end - - local result = pandoc.List() - - for i = 1, n do result:insert(self[i]) end - - return result -end - -function dump(o) - if type(o) == 'table' then - local s = '{ ' - for k, v in pairs(o) do - if type(k) ~= 'number' then k = '"' .. k .. '"' end - s = s .. '[' .. k .. '] = ' .. dump(v) .. ',' - end - return s .. '} ' - else - return tostring(o) - end -end - -function page_sort(order) - return function(p1, p2) - if p1.position then - if p2.position then - return tonumber(p1.position) < tonumber(p2.position) - else - return true - end - elseif p2.position then - return false - elseif order == "date_desc" then - if p1.last_update then - if p2.last_update then - return p1.last_update.yyyy_mm_dd > p2.last_update.yyyy_mm_dd - else - return true - end - else - return false - end - else - return p1.title:upper() < p2.title:upper() - end - end -end - -function slug(str) - return str:lower():gsub("[^ a-z]", ""):gsub("[ ]+", "-") -end - -function format_date(date) - if not date then return date end - - date = pandoc.utils.normalize_date(pandoc.utils.stringify(date)) - local year, month, day = date:match("(%d%d%d%d)-(%d%d)-(%d%d)") - if not year then return nil end - - local time = os.time({ year = tonumber(year), month = tonumber(month), day = tonumber(day) }) - return { - yyyy_mm_dd = os.date("%F", time), - yyyy = os.date("%Y", time), - mm = os.date("%m", time), - dd = os.date("%d", time), - rfc3339 = os.date("%FT%T+00:00", time), - long = os.date("%B %d, %Y", time), - short = os.date("%b %d, %Y", time), - } -end - -function make_absolute(rel, base) - return path.is_absolute(rel) and rel or path.join({ path.directory(base), rel }) -end - -function resolve_url(site_url, ref_file, target_file) - target_file = target_file:gsub("/index%.html$", "/") - - 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:sub(1, 1) == "/" and (site_url .. abs)) or abs - - return { abs = abs, rel = rel, full = full } -end - -function resolve_layout(depth) - local layout = "categorized_list" - - if depth == 0 then - layout = "page" - elseif depth == 1 then - layout = "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) - namespace = pandoc.utils.stringify(namespace) - - local root = "index" - if namespace ~= "" then root = namespace:gsub("^/([^/]*).*$", "%1") end - - return { root = { id = root, ["is_" .. root] = true }, full = namespace } -end - -function prep_menu(active_id, main_menu) - local active_item = nil - local items = pandoc.List() - - for i = 1, #main_menu do - local item = main_menu[i] - local active = pandoc.utils.stringify(item.id) == active_id - item.active = active - if active then active_item = item end - if not item.hidden or item.active then items:insert(item) end - end - - return { items = items, active = active_item } -end - -function process_pages(global, 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) - if not p.unlisted then - pages_all:insert(p) - if p.last_update then pages_date_desc:insert(p) end - end - end - - pages_all:sort(page_sort(order)) - pages_date_desc:sort(page_sort("date_desc")) - - local pages_data = { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } - - return pages_data -end - -function find_depth(pages) - local depth = 0 - - if pages 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 - end - - return depth -end - -function d1_page_to_list_item(meta, p) - return { - title = p.title, - subtitle = p.subtitle, - date = p.date, - last_update = p.last_update, - schema_type = p.schema_type, - position = p.position, - url = p.url, - rel = p.rel, - slug = p.slug, - thumbnail = p.thumbnail, - icon = p.icon or meta.icon, - post_icon = p.post_icon or meta.list_post_icon, - indicator = meta.list_read_indicators, - } -end - -function d2_page_to_list_item(meta, cat, p, set_cat_title) - return { - title = p.title, - subtitle = p.subtitle, - category = set_cat_title and cat.title, - date = p.date, - last_update = p.last_update, - schema_type = p.schema_type, - position = p.position, - url = p.url, - rel = p.rel, - slug = p.slug, - thumbnail = p.thumbnail, - icon = p.icon or cat.icon, - post_icon = p.post_icon or cat.list_post_icon or meta.list_post_icon, - indicator = cat.list_read_indicators, - } -end - -function cat_to_list_cat(cat, allItems) - local limit = cat.list_limit or 9999 - local items = allItems:take(limit) - local omitted = #allItems - #items - - return { - title = cat.title, - description = (cat.description and pandoc.MetaBlocks(pandoc.Para(cat.description))) or - (not cat.no_description and cat.content), - last_update = cat.last_update, - schema_type = cat.schema_type, - url = cat.url, - slug = cat.slug, - layout = cat.list_layout, - items = items, - total = tostring(#allItems), - omitted = omitted ~= 0 and tostring(omitted), - } -end - -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) - end - - if meta.depth == 2 then - return meta.pages.all - :map(function(cat) - local allItems = ((cat.pages and cat.pages.all) or pandoc.List()) - :map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) - - return cat_to_list_cat(cat, allItems) - end) - :filter(function(cat) return #cat.items ~= 0 end) - end - - if meta.depth == 3 then - return meta.pages.all - :map(function(cat) - local allItems = (cat.pages and cat.pages.all or pandoc.List()):flatMap(function(c) - if not c.pages or not cat.list_flatten then - return pandoc.List({ d1_page_to_list_item(cat, c) }) - else - return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end) - end - end) - allItems:sort(page_sort(cat.list_order)) - - return cat_to_list_cat(cat, allItems) - end) - :filter(function(cat) return #cat.items ~= 0 end) - end -end - -function process(global, meta) - meta.namespace = resolve_namespace(meta.namespace) - meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") - 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) - meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" - meta.slug = slug(meta.title) - meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork" - if meta.list_order then meta.list_order = pandoc.utils.stringify(meta.list_order) end - meta.list_layout = meta.list_layout and prep_layout(meta.list_layout) - if meta.list_limit then meta.list_limit = tonumber(pandoc.utils.stringify(meta.list_limit)) end - if meta.position then meta.position = pandoc.utils.stringify(meta.position) end - - if meta.feed then - if meta.file_out:match(".html$") then - meta.feed = { - url = resolve_url(global.site.url, global.file_out, meta.file_out:gsub(".html$", ".xml")), - } - else - meta.page = { - url = resolve_url(global.site.url, global.file_out, meta.file_out:gsub(".xml$", ".html")), - } - end - end - - if meta.thumbnail then - meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), - meta.file_out) - meta.thumbnail = resolve_url(global.site.url, global.file_out, meta.thumbnail) - end - - if meta.menus and meta.menus.main then - meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) - end - - meta.pages = process_pages(global, meta.list_order, meta.pages) - meta.depth = find_depth(meta.pages) - meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) - - if meta.date then - meta.date = format_date(meta.date) - elseif meta.pages and #meta.pages.date_desc ~= 0 then - meta.date = meta.pages.date_desc[1].date - end - - if meta.last_update then - meta.last_update = format_date(meta.last_update) - elseif meta.pages and #meta.pages.date_desc ~= 0 then - meta.last_update = meta.pages.date_desc[1].last_update - elseif meta.date then - 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) -end diff --git a/scripts/metadata_tpl.json b/scripts/metadata_tpl.json deleted file mode 100755 index fb36f0f..0000000 --- a/scripts/metadata_tpl.json +++ /dev/null @@ -1 +0,0 @@ -$meta-json$ -- cgit v1.2.3-70-g09d2