summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-08-02 20:56:45 +0200
committerVolpeon <git@volpeon.ink>2022-08-02 20:56:45 +0200
commit944a735c39a27fc86569c585f2805837b61adb60 (patch)
treec35f9e0c834c35a395aa58edbcebd8b5e9c83d70
parentStyle fix for card list 'list' layout gap on <=sm (diff)
downloadvolpeon.ink-944a735c39a27fc86569c585f2805837b61adb60.tar.gz
volpeon.ink-944a735c39a27fc86569c585f2805837b61adb60.tar.bz2
volpeon.ink-944a735c39a27fc86569c585f2805837b61adb60.zip
Slightly tidied up metadata handling
-rw-r--r--Makefile15
-rw-r--r--filters/lib/common.lua26
-rw-r--r--filters/vars.lua2
-rw-r--r--scripts/lib/common.lua54
-rw-r--r--scripts/metadata.lua71
5 files changed, 84 insertions, 84 deletions
diff --git a/Makefile b/Makefile
index cfc583f..863fca1 100644
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@ static_files: $(STATIC_FILES)
44 44
45.SECONDEXPANSION: 45.SECONDEXPANSION:
46 46
47namespace = $(patsubst %/index,%,$(patsubst %.json,%,$(patsubst $(2)%,%,$(1)))) 47namespace = $(patsubst %/index,%,$(basename $(patsubst $(2)%,%,$(1))))
48 48
49subpages = $(patsubst content/%.md,.cache/meta/%.json, \ 49subpages = $(patsubst content/%.md,.cache/meta/%.json, \
50 $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ 50 $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \
@@ -64,7 +64,6 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \
64 --no-highlight \ 64 --no-highlight \
65 --metadata-file "$@.pages" \ 65 --metadata-file "$@.pages" \
66 --template scripts/metadata.json \ 66 --template scripts/metadata.json \
67 --metadata mode="$(MODE)" \
68 --metadata namespace="$(NAMESPACE)" \ 67 --metadata namespace="$(NAMESPACE)" \
69 --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ 68 --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \
70 $(PANDOC_FILTERS) \ 69 $(PANDOC_FILTERS) \
@@ -78,8 +77,8 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \
78 --lua-filter scripts/subpages.lua \ 77 --lua-filter scripts/subpages.lua \
79 $(GLOBAL_METADATA) \ 78 $(GLOBAL_METADATA) \
80 --metadata-file "$@.meta" \ 79 --metadata-file "$@.meta" \
81 --metadata mode="$(MODE)" \ 80 --metadata build.mode="$(MODE)" \
82 --metadata file_out="$@" \ 81 --metadata build.file_out="$@" \
83 $(PANDOC_FILTERS) \ 82 $(PANDOC_FILTERS) \
84 -o "$@.content" "$<" 83 -o "$@.content" "$<"
85 jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" 84 jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@"
@@ -102,9 +101,9 @@ out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLAT
102 --lua-filter scripts/metadata.lua \ 101 --lua-filter scripts/metadata.lua \
103 $(GLOBAL_METADATA) \ 102 $(GLOBAL_METADATA) \
104 --metadata-file .cache/assets.json \ 103 --metadata-file .cache/assets.json \
105 --metadata mode="$(MODE)" \
106 --metadata-file "$(filter .cache/meta/%.json,$^)" \ 104 --metadata-file "$(filter .cache/meta/%.json,$^)" \
107 --metadata file_out="$@" \ 105 --metadata build.mode="$(MODE)" \
106 --metadata build.file_out="$@" \
108 $(PANDOC_FILTERS) \ 107 $(PANDOC_FILTERS) \
109 -o "$@" "$<" 108 -o "$@" "$<"
110 109
@@ -121,8 +120,8 @@ out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml
121 --lua-filter scripts/metadata.lua \ 120 --lua-filter scripts/metadata.lua \
122 $(GLOBAL_METADATA) \ 121 $(GLOBAL_METADATA) \
123 --metadata-file "$(filter .cache/meta/%.json,$^)" \ 122 --metadata-file "$(filter .cache/meta/%.json,$^)" \
124 --metadata mode="$(MODE)" \ 123 --metadata build.mode="$(MODE)" \
125 --metadata file_out="$@" \ 124 --metadata build.file_out="$@" \
126 $(PANDOC_FILTERS) \ 125 $(PANDOC_FILTERS) \
127 -o "$@" "$<" 126 -o "$@" "$<"
128 127
diff --git a/filters/lib/common.lua b/filters/lib/common.lua
index 4d44ff3..d6f92e0 100644
--- a/filters/lib/common.lua
+++ b/filters/lib/common.lua
@@ -12,30 +12,6 @@ function wide(el)
12 return els 12 return els
13end 13end
14 14
15function dump(o)
16 if type(o) == 'table' then
17 local s = '{ '
18 for k, v in pairs(o) do
19 if type(k) ~= 'number' then k = '"' .. k .. '"' end
20 s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
21 end
22 return s .. '} '
23 else
24 return tostring(o)
25 end
26end
27
28function string.split(str, sep)
29 sep = sep or '%s'
30
31 local parts = pandoc.List()
32
33 for field, s in str:gmatch("([^" .. sep .. "]*)(" .. sep .. "?)") do
34 parts:insert(field)
35 if s == "" then return parts end
36 end
37end
38
39return { 15return {
40 wide = wide, dump = dump 16 wide = wide
41} 17}
diff --git a/filters/vars.lua b/filters/vars.lua
index b0fa66c..99cedc4 100644
--- a/filters/vars.lua
+++ b/filters/vars.lua
@@ -1,4 +1,4 @@
1local common = require 'filters.lib.common' 1local common = require 'scripts.lib.common'
2 2
3local vars = {} 3local vars = {}
4 4
diff --git a/scripts/lib/common.lua b/scripts/lib/common.lua
new file mode 100644
index 0000000..80b81ba
--- /dev/null
+++ b/scripts/lib/common.lua
@@ -0,0 +1,54 @@
1function dump(o)
2 if type(o) == 'table' then
3 local s = '{ '
4 for k, v in pairs(o) do
5 if type(k) ~= 'number' then k = '"' .. k .. '"' end
6 s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
7 end
8 return s .. '} '
9 else
10 return tostring(o)
11 end
12end
13
14function string.split(str, sep)
15 sep = sep or '%s'
16
17 local parts = pandoc.List()
18
19 for field, s in str:gmatch("([^" .. sep .. "]*)(" .. sep .. "?)") do
20 parts:insert(field)
21 if s == "" then return parts end
22 end
23end
24
25function pandoc.List:flatten()
26 local result = pandoc.List()
27
28 for i = 1, #self do result:extend(self[i]) end
29
30 return result
31end
32
33function pandoc.List:flatMap(fn)
34 local mapped = self:map(fn)
35 local result = pandoc.List()
36
37 for i = 1, #mapped do result:extend(mapped[i]) end
38
39 return result
40end
41
42function pandoc.List:take(n)
43 if n >= #self then return self end
44
45 local result = pandoc.List()
46
47 for i = 1, n do result:insert(self[i]) end
48
49 return result
50end
51
52return {
53 dump = dump
54}
diff --git a/scripts/metadata.lua b/scripts/metadata.lua
index a451040..cb6c6e6 100644
--- a/scripts/metadata.lua
+++ b/scripts/metadata.lua
@@ -1,44 +1,5 @@
1local path = require 'pandoc.path' 1local path = require 'pandoc.path'
2 2local common = require 'scripts.lib.common'
3function pandoc.List:flatten()
4 local result = pandoc.List()
5
6 for i = 1, #self do result:extend(self[i]) end
7
8 return result
9end
10
11function pandoc.List:flatMap(fn)
12 local mapped = self:map(fn)
13 local result = pandoc.List()
14
15 for i = 1, #mapped do result:extend(mapped[i]) end
16
17 return result
18end
19
20function pandoc.List:take(n)
21 if n >= #self then return self end
22
23 local result = pandoc.List()
24
25 for i = 1, n do result:insert(self[i]) end
26
27 return result
28end
29
30function dump(o)
31 if type(o) == 'table' then
32 local s = '{ '
33 for k, v in pairs(o) do
34 if type(k) ~= 'number' then k = '"' .. k .. '"' end
35 s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
36 end
37 return s .. '} '
38 else
39 return tostring(o)
40 end
41end
42 3
43function page_sort(order) 4function page_sort(order)
44 return function(p1, p2) 5 return function(p1, p2)
@@ -145,13 +106,13 @@ function prep_menu(active_id, main_menu)
145 return { items = items, active = active_item } 106 return { items = items, active = active_item }
146end 107end
147 108
148function process_pages(global, order, pages_by_id) 109function process_pages(global, build, order, pages_by_id)
149 local pages_all = pandoc.List() 110 local pages_all = pandoc.List()
150 local pages_date_desc = pandoc.List() 111 local pages_date_desc = pandoc.List()
151 112
152 if pages_by_id then 113 if pages_by_id then
153 for _, page in pairs(pages_by_id) do 114 for _, page in pairs(pages_by_id) do
154 local p = process(global, page) 115 local p = process(global, build, page)
155 if not p.unlisted then 116 if not p.unlisted then
156 pages_all:insert(p) 117 pages_all:insert(p)
157 if p.last_update then pages_date_desc:insert(p) end 118 if p.last_update then pages_date_desc:insert(p) end
@@ -286,13 +247,13 @@ function generate_list(meta)
286 end 247 end
287end 248end
288 249
289function process(global, meta) 250function process(global, build, meta)
290 meta.namespace = resolve_namespace(meta.namespace) 251 meta.namespace = resolve_namespace(meta.namespace)
291 meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") 252 meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "")
292 meta.unlisted = meta.unlisted or (meta.draft and global.mode ~= "dev") 253 meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev")
293 meta.redirect = meta.url and true 254 meta.redirect = meta.url and true
294 meta.url = meta.url and pandoc.utils.stringify(meta.url) 255 meta.url = meta.url and pandoc.utils.stringify(meta.url)
295 meta.url = resolve_url(global.site.url, global.file_out, meta.url or meta.file_out) 256 meta.url = resolve_url(global.site.url, build.file_out, meta.url or meta.file_out)
296 meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" 257 meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or ""
297 meta.slug = slug(meta.title) 258 meta.slug = slug(meta.title)
298 meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork" 259 meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork"
@@ -304,11 +265,11 @@ function process(global, meta)
304 if meta.feed then 265 if meta.feed then
305 if meta.file_out:match(".html$") then 266 if meta.file_out:match(".html$") then
306 meta.feed = { 267 meta.feed = {
307 url = resolve_url(global.site.url, global.file_out, meta.file_out:gsub(".html$", ".xml")), 268 url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")),
308 } 269 }
309 else 270 else
310 meta.page = { 271 meta.page = {
311 url = resolve_url(global.site.url, global.file_out, meta.file_out:gsub(".xml$", ".html")), 272 url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")),
312 } 273 }
313 end 274 end
314 end 275 end
@@ -316,14 +277,14 @@ function process(global, meta)
316 if meta.thumbnail then 277 if meta.thumbnail then
317 meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), 278 meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail),
318 meta.file_out) 279 meta.file_out)
319 meta.thumbnail = resolve_url(global.site.url, global.file_out, meta.thumbnail) 280 meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail)
320 end 281 end
321 282
322 if meta.menus and meta.menus.main then 283 if meta.menus and meta.menus.main then
323 meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) 284 meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main)
324 end 285 end
325 286
326 meta.pages = process_pages(global, meta.list_order, meta.pages) 287 meta.pages = process_pages(global, build, meta.list_order, meta.pages)
327 meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) 288 meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth))
328 289
329 if meta.last_update then 290 if meta.last_update then
@@ -348,8 +309,18 @@ function process(global, meta)
348end 309end
349 310
350function Meta(meta) 311function Meta(meta)
312 local build = {}
313
314 for key, value in pairs(meta) do
315 local suffix = key:match('^build.(.*)$')
316
317 if suffix then
318 build[suffix] = value
319 end
320 end
321
351 meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") 322 meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "")
352 323
353 find_depth(meta) 324 find_depth(meta)
354 return process(meta, meta) 325 return process(meta, build, meta)
355end 326end