diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/metadata.lua | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/scripts/metadata.lua b/scripts/metadata.lua index 98ad9e5..9cb9970 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua | |||
@@ -162,9 +162,7 @@ function process_pages(global, order, pages_by_id) | |||
162 | pages_date_desc:sort(page_sort("date_desc")) | 162 | pages_date_desc:sort(page_sort("date_desc")) |
163 | end | 163 | end |
164 | 164 | ||
165 | local pages_data = { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } | 165 | return { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } |
166 | |||
167 | return pages_data | ||
168 | end | 166 | end |
169 | 167 | ||
170 | function find_depth(pages) | 168 | function find_depth(pages) |
@@ -240,21 +238,17 @@ function cat_to_list_cat(cat, allItems) | |||
240 | } | 238 | } |
241 | end | 239 | end |
242 | 240 | ||
243 | function generate_list(global, meta) | 241 | function generate_list(meta) |
244 | if meta.depth < 1 then return nil end | 242 | if meta.depth < 1 then return nil end |
245 | 243 | ||
246 | if meta.depth == 1 then | 244 | if meta.depth == 1 then |
247 | return meta.pages.all | 245 | return meta.pages.all:map(function(p) return d1_page_to_list_item(meta, p) end) |
248 | :map(function(p) return d1_page_to_list_item(meta, p) end) | ||
249 | :filter(function(p) return not p.draft or global.mode == "dev" end) | ||
250 | end | 246 | end |
251 | 247 | ||
252 | if meta.depth == 2 then | 248 | if meta.depth == 2 then |
253 | return meta.pages.all | 249 | return meta.pages.all |
254 | :map(function(cat) | 250 | :map(function(cat) |
255 | local allItems = cat.pages.all | 251 | local allItems = cat.pages.all:map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) |
256 | :map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) | ||
257 | :filter(function(p) return not p.draft or global.mode == "dev" end) | ||
258 | 252 | ||
259 | return cat_to_list_cat(cat, allItems) | 253 | return cat_to_list_cat(cat, allItems) |
260 | end) | 254 | end) |
@@ -264,15 +258,13 @@ function generate_list(global, meta) | |||
264 | if meta.depth == 3 then | 258 | if meta.depth == 3 then |
265 | local list = meta.pages.all | 259 | local list = meta.pages.all |
266 | :map(function(cat) | 260 | :map(function(cat) |
267 | local allItems = cat.pages.all | 261 | local allItems = cat.pages.all:flatMap(function(c) |
268 | :flatMap(function(c) | 262 | if cat.list_flatten and c.depth ~= 0 then |
269 | if #c.pages.all ~= 0 and cat.list_flatten then | 263 | return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end) |
270 | return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end) | 264 | else |
271 | else | 265 | return pandoc.List({ d1_page_to_list_item(cat, c) }) |
272 | return pandoc.List({ d1_page_to_list_item(cat, c) }) | 266 | end |
273 | end | 267 | end) |
274 | end) | ||
275 | :filter(function(p) return not p.draft or global.mode == "dev" end) | ||
276 | 268 | ||
277 | allItems:sort(page_sort(cat.list_order)) | 269 | allItems:sort(page_sort(cat.list_order)) |
278 | 270 | ||
@@ -287,6 +279,7 @@ end | |||
287 | function process(global, meta) | 279 | function process(global, meta) |
288 | meta.namespace = resolve_namespace(meta.namespace) | 280 | meta.namespace = resolve_namespace(meta.namespace) |
289 | meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") | 281 | meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") |
282 | meta.unlisted = meta.unlisted or (meta.draft and global.mode ~= "dev") | ||
290 | meta.redirect = meta.url and true | 283 | meta.redirect = meta.url and true |
291 | meta.url = meta.url and pandoc.utils.stringify(meta.url) | 284 | meta.url = meta.url and pandoc.utils.stringify(meta.url) |
292 | meta.url = resolve_url(global.site.url, global.file_out, meta.url or meta.file_out) | 285 | meta.url = resolve_url(global.site.url, global.file_out, meta.url or meta.file_out) |
@@ -321,7 +314,7 @@ function process(global, meta) | |||
321 | end | 314 | end |
322 | 315 | ||
323 | meta.pages = process_pages(global, meta.list_order, meta.pages) | 316 | meta.pages = process_pages(global, meta.list_order, meta.pages) |
324 | meta.depth = find_depth(meta.pages) | 317 | meta.depth = meta.depth and tonumber(pandoc.utils.stringify(meta.depth)) or find_depth(meta.pages) |
325 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) | 318 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) |
326 | 319 | ||
327 | if meta.last_update then | 320 | if meta.last_update then |
@@ -338,7 +331,7 @@ function process(global, meta) | |||
338 | meta.date = meta.last_update | 331 | meta.date = meta.last_update |
339 | end | 332 | end |
340 | 333 | ||
341 | meta.list = generate_list(global, meta) | 334 | meta.list = generate_list(meta) |
342 | 335 | ||
343 | return meta | 336 | return meta |
344 | end | 337 | end |