summaryrefslogtreecommitdiffstats
path: root/scripts/metadata.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/metadata.lua')
-rw-r--r--scripts/metadata.lua89
1 files changed, 45 insertions, 44 deletions
diff --git a/scripts/metadata.lua b/scripts/metadata.lua
index cb6c6e6..7d9206f 100644
--- a/scripts/metadata.lua
+++ b/scripts/metadata.lua
@@ -111,8 +111,8 @@ function process_pages(global, build, order, pages_by_id)
111 local pages_date_desc = pandoc.List() 111 local pages_date_desc = pandoc.List()
112 112
113 if pages_by_id then 113 if pages_by_id then
114 for _, page in pairs(pages_by_id) do 114 for _, p in pairs(pages_by_id) do
115 local p = process(global, build, page) 115 process(global, build, p)
116 if not p.unlisted then 116 if not p.unlisted then
117 pages_all:insert(p) 117 pages_all:insert(p)
118 if p.last_update then pages_date_desc:insert(p) end 118 if p.last_update then pages_date_desc:insert(p) end
@@ -133,19 +133,35 @@ function find_depth(meta)
133 133
134 local depth = 0 134 local depth = 0
135 135
136 if meta.pages then 136 for _, p in pairs(meta.pages) do
137 for _, page in pairs(meta.pages) do 137 find_depth(p)
138 local p = find_depth(page) 138 if not p.unlisted then
139 if not p.unlisted then 139 local d = p.depth + 1
140 local d = p.depth + 1 140 if d > depth then depth = d end
141 if d > depth then depth = d end
142 end
143 end 141 end
144 end 142 end
145 143
146 meta.depth = depth 144 meta.depth = depth
145end
147 146
148 return meta 147function resolve_urls(global, build, meta)
148 meta.url = resolve_url(global.site.url, build.file_out, meta.url)
149
150 if meta.feed then
151 if meta.file_out:match(".html$") then
152 meta.feed = {
153 url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")),
154 }
155 else
156 meta.page = {
157 url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")),
158 }
159 end
160 end
161
162 if meta.thumbnail then
163 meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail)
164 end
149end 165end
150 166
151function d1_page_to_list_item(meta, p) 167function d1_page_to_list_item(meta, p)
@@ -249,40 +265,20 @@ end
249 265
250function process(global, build, meta) 266function process(global, build, meta)
251 meta.namespace = resolve_namespace(meta.namespace) 267 meta.namespace = resolve_namespace(meta.namespace)
252 meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") 268 meta.file_out = pandoc.utils.stringify(meta.file_out)
253 meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") 269 meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev")
254 meta.redirect = meta.url and true 270 meta.redirect = meta.url and true
255 meta.url = meta.url and pandoc.utils.stringify(meta.url) 271 meta.url = meta.url and pandoc.utils.stringify(meta.url) or meta.file_out
256 meta.url = resolve_url(global.site.url, build.file_out, meta.url or meta.file_out) 272 meta.title = meta.title and pandoc.utils.stringify(meta.title) or ""
257 meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or ""
258 meta.slug = slug(meta.title) 273 meta.slug = slug(meta.title)
259 meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork" 274 meta.schema_type = meta.schema_type and pandoc.utils.stringify(meta.schema_type) or "CreativeWork"
260 if meta.list_order then meta.list_order = pandoc.utils.stringify(meta.list_order) end 275 meta.list_order = meta.list_order and pandoc.utils.stringify(meta.list_order)
261 meta.list_layout = prep_layout(meta.list_layout or "list") 276 meta.list_layout = prep_layout(meta.list_layout or "list")
262 if meta.list_limit then meta.list_limit = tonumber(pandoc.utils.stringify(meta.list_limit)) end 277 meta.list_limit = meta.list_limit and tonumber(pandoc.utils.stringify(meta.list_limit))
263 if meta.position then meta.position = tonumber(pandoc.utils.stringify(meta.position)) end 278 meta.position = meta.position and tonumber(pandoc.utils.stringify(meta.position))
279 meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), meta.file_out)
264 280
265 if meta.feed then 281 resolve_urls(global, build, meta)
266 if meta.file_out:match(".html$") then
267 meta.feed = {
268 url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")),
269 }
270 else
271 meta.page = {
272 url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")),
273 }
274 end
275 end
276
277 if meta.thumbnail then
278 meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail),
279 meta.file_out)
280 meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail)
281 end
282
283 if meta.menus and meta.menus.main then
284 meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main)
285 end
286 282
287 meta.pages = process_pages(global, build, meta.list_order, meta.pages) 283 meta.pages = process_pages(global, build, meta.list_order, meta.pages)
288 meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) 284 meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth))
@@ -302,10 +298,6 @@ function process(global, build, meta)
302 end 298 end
303 299
304 meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd 300 meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd
305
306 meta.list = generate_list(meta)
307
308 return meta
309end 301end
310 302
311function Meta(meta) 303function Meta(meta)
@@ -316,11 +308,20 @@ function Meta(meta)
316 308
317 if suffix then 309 if suffix then
318 build[suffix] = value 310 build[suffix] = value
311 meta[key] = nil
319 end 312 end
320 end 313 end
321 314
322 meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") 315 meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "")
323 316
324 find_depth(meta) 317 find_depth(meta)
325 return process(meta, build, meta) 318 process(meta, build, meta)
319
320 meta.list = generate_list(meta)
321
322 if meta.menus and meta.menus.main then
323 meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main)
324 end
325
326 return meta
326end 327end