diff options
author | Volpeon <git@volpeon.ink> | 2022-08-03 21:32:51 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2022-08-03 21:32:51 +0200 |
commit | 82ee57d61c1ef24f75dc2d50ddeba756114fa522 (patch) | |
tree | 88b0b634caa664b9ea2d4dfd993d18e9aa9ed9fb | |
parent | Website gen adjustments (diff) | |
download | volpeon.ink-82ee57d61c1ef24f75dc2d50ddeba756114fa522.tar.gz volpeon.ink-82ee57d61c1ef24f75dc2d50ddeba756114fa522.tar.bz2 volpeon.ink-82ee57d61c1ef24f75dc2d50ddeba756114fa522.zip |
Code reorganization
-rw-r--r-- | scripts/metadata.lua | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/scripts/metadata.lua b/scripts/metadata.lua index 7d9206f..6aa679a 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua | |||
@@ -106,24 +106,25 @@ function prep_menu(active_id, main_menu) | |||
106 | return { items = items, active = active_item } | 106 | return { items = items, active = active_item } |
107 | end | 107 | end |
108 | 108 | ||
109 | function process_pages(global, build, order, pages_by_id) | 109 | function process_pages(global, build, meta) |
110 | local order = meta.list_order | ||
111 | |||
110 | local pages_all = pandoc.List() | 112 | local pages_all = pandoc.List() |
111 | local pages_date_desc = pandoc.List() | 113 | local pages_date_desc = pandoc.List() |
112 | 114 | ||
113 | if pages_by_id then | 115 | for _, p in pairs(meta.pages) do |
114 | for _, p in pairs(pages_by_id) do | 116 | process(global, build, p) |
115 | process(global, build, p) | ||
116 | if not p.unlisted then | ||
117 | pages_all:insert(p) | ||
118 | if p.last_update then pages_date_desc:insert(p) end | ||
119 | end | ||
120 | end | ||
121 | 117 | ||
122 | pages_all:sort(page_sort(order)) | 118 | if not p.unlisted then |
123 | pages_date_desc:sort(page_sort("date_desc")) | 119 | pages_all:insert(p) |
120 | if p.last_update then pages_date_desc:insert(p) end | ||
121 | end | ||
124 | end | 122 | end |
125 | 123 | ||
126 | return { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } | 124 | pages_all:sort(page_sort(order)) |
125 | pages_date_desc:sort(page_sort("date_desc")) | ||
126 | |||
127 | meta.pages = { all = pages_all, date_desc = pages_date_desc, by_id = meta.pages } | ||
127 | end | 128 | end |
128 | 129 | ||
129 | function find_depth(meta) | 130 | function find_depth(meta) |
@@ -162,6 +163,28 @@ function resolve_urls(global, build, meta) | |||
162 | if meta.thumbnail then | 163 | if meta.thumbnail then |
163 | meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) | 164 | meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) |
164 | end | 165 | end |
166 | |||
167 | -- for _, p in pairs(meta.pages.by_id) do | ||
168 | -- resolve_urls(global, build, p) | ||
169 | -- end | ||
170 | end | ||
171 | |||
172 | function resolve_dates(meta) | ||
173 | if meta.last_update then | ||
174 | meta.last_update = format_date(meta.last_update) | ||
175 | elseif #meta.pages.date_desc ~= 0 then | ||
176 | meta.last_update = meta.pages.date_desc[1].last_update | ||
177 | elseif meta.date then | ||
178 | meta.last_update = format_date(meta.date) | ||
179 | end | ||
180 | |||
181 | if meta.date then | ||
182 | meta.date = format_date(meta.date) | ||
183 | elseif meta.last_update then | ||
184 | meta.date = meta.last_update | ||
185 | end | ||
186 | |||
187 | meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd | ||
165 | end | 188 | end |
166 | 189 | ||
167 | function d1_page_to_list_item(meta, p) | 190 | function d1_page_to_list_item(meta, p) |
@@ -226,7 +249,7 @@ function cat_to_list_cat(cat, allItems) | |||
226 | end | 249 | end |
227 | 250 | ||
228 | function generate_list(meta) | 251 | function generate_list(meta) |
229 | if meta.depth < 1 then return nil end | 252 | if meta.depth < 1 then return pandoc.List() end |
230 | 253 | ||
231 | if meta.depth == 1 then | 254 | if meta.depth == 1 then |
232 | return meta.pages.all:map(function(p) return d1_page_to_list_item(meta, p) end) | 255 | return meta.pages.all:map(function(p) return d1_page_to_list_item(meta, p) end) |
@@ -263,7 +286,7 @@ function generate_list(meta) | |||
263 | end | 286 | end |
264 | end | 287 | end |
265 | 288 | ||
266 | function process(global, build, meta) | 289 | function process_base(build, meta) |
267 | meta.namespace = resolve_namespace(meta.namespace) | 290 | meta.namespace = resolve_namespace(meta.namespace) |
268 | meta.file_out = pandoc.utils.stringify(meta.file_out) | 291 | meta.file_out = pandoc.utils.stringify(meta.file_out) |
269 | meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") | 292 | meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") |
@@ -277,27 +300,14 @@ function process(global, build, meta) | |||
277 | meta.list_limit = meta.list_limit and tonumber(pandoc.utils.stringify(meta.list_limit)) | 300 | meta.list_limit = meta.list_limit and tonumber(pandoc.utils.stringify(meta.list_limit)) |
278 | meta.position = meta.position and tonumber(pandoc.utils.stringify(meta.position)) | 301 | 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) | 302 | meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), meta.file_out) |
280 | |||
281 | resolve_urls(global, build, meta) | ||
282 | |||
283 | meta.pages = process_pages(global, build, meta.list_order, meta.pages) | ||
284 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) | 303 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) |
304 | end | ||
285 | 305 | ||
286 | if meta.last_update then | 306 | function process(global, build, meta) |
287 | meta.last_update = format_date(meta.last_update) | 307 | process_base(build, meta) |
288 | elseif #meta.pages.date_desc ~= 0 then | 308 | resolve_urls(global, build, meta) |
289 | meta.last_update = meta.pages.date_desc[1].last_update | 309 | process_pages(global, build, meta) |
290 | elseif meta.date then | 310 | resolve_dates(meta) |
291 | meta.last_update = format_date(meta.date) | ||
292 | end | ||
293 | |||
294 | if meta.date then | ||
295 | meta.date = format_date(meta.date) | ||
296 | elseif meta.last_update then | ||
297 | meta.date = meta.last_update | ||
298 | end | ||
299 | |||
300 | meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd | ||
301 | end | 311 | end |
302 | 312 | ||
303 | function Meta(meta) | 313 | function Meta(meta) |