summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/metadata.lua57
1 files changed, 33 insertions, 24 deletions
diff --git a/scripts/metadata.lua b/scripts/metadata.lua
index 872034c..98ad9e5 100644
--- a/scripts/metadata.lua
+++ b/scripts/metadata.lua
@@ -170,14 +170,10 @@ end
170function find_depth(pages) 170function find_depth(pages)
171 local depth = 0 171 local depth = 0
172 172
173 if #pages.all ~= 0 then 173 for i = 1, #pages.all do
174 for i = 1, #pages.all do 174 local p = pages.all[i]
175 local p = pages.all[i] 175 local d = tonumber(p.depth) + 1
176 local d = tonumber(p.depth) 176 if d > depth then depth = d end
177 if d > depth then depth = d end
178 end
179
180 depth = depth + 1
181 end 177 end
182 178
183 return depth 179 return depth
@@ -187,9 +183,11 @@ function d1_page_to_list_item(meta, p)
187 return { 183 return {
188 title = p.title, 184 title = p.title,
189 subtitle = p.subtitle, 185 subtitle = p.subtitle,
190 date = meta.list_order == "date_desc" and p.date, 186 date = p.date,
191 last_update = meta.list_order == "date_desc" and p.last_update, 187 last_update = p.last_update,
188 show_date = meta.list_order == "date_desc",
192 schema_type = p.schema_type, 189 schema_type = p.schema_type,
190 draft = p.draft,
193 position = p.position, 191 position = p.position,
194 url = p.url, 192 url = p.url,
195 rel = p.rel, 193 rel = p.rel,
@@ -206,9 +204,11 @@ function d2_page_to_list_item(meta, cat, p, set_cat_title)
206 title = p.title, 204 title = p.title,
207 subtitle = p.subtitle, 205 subtitle = p.subtitle,
208 category = set_cat_title and cat.title, 206 category = set_cat_title and cat.title,
209 date = cat.list_order == "date_desc" and p.date, 207 date = p.date,
210 last_update = cat.list_order == "date_desc" and p.last_update, 208 last_update = p.last_update,
209 show_date = cat.list_order == "date_desc",
211 schema_type = p.schema_type, 210 schema_type = p.schema_type,
211 draft = p.draft,
212 position = p.position, 212 position = p.position,
213 url = p.url, 213 url = p.url,
214 rel = p.rel, 214 rel = p.rel,
@@ -240,17 +240,21 @@ function cat_to_list_cat(cat, allItems)
240 } 240 }
241end 241end
242 242
243function generate_list(meta) 243function generate_list(global, meta)
244 if meta.depth < 1 then return nil end 244 if meta.depth < 1 then return nil end
245 245
246 if meta.depth == 1 then 246 if meta.depth == 1 then
247 return meta.pages.all:map(function(p) return d1_page_to_list_item(meta, p) end) 247 return meta.pages.all
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)
248 end 250 end
249 251
250 if meta.depth == 2 then 252 if meta.depth == 2 then
251 return meta.pages.all 253 return meta.pages.all
252 :map(function(cat) 254 :map(function(cat)
253 local allItems = cat.pages.all:map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) 255 local allItems = cat.pages.all
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)
254 258
255 return cat_to_list_cat(cat, allItems) 259 return cat_to_list_cat(cat, allItems)
256 end) 260 end)
@@ -258,20 +262,25 @@ function generate_list(meta)
258 end 262 end
259 263
260 if meta.depth == 3 then 264 if meta.depth == 3 then
261 return meta.pages.all 265 local list = meta.pages.all
262 :map(function(cat) 266 :map(function(cat)
263 local allItems = cat.pages.all:flatMap(function(c) 267 local allItems = cat.pages.all
264 if #c.pages.all ~= 0 and cat.list_flatten then 268 :flatMap(function(c)
265 return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end) 269 if #c.pages.all ~= 0 and cat.list_flatten then
266 else 270 return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end)
267 return pandoc.List({ d1_page_to_list_item(cat, c) }) 271 else
268 end 272 return pandoc.List({ d1_page_to_list_item(cat, c) })
269 end) 273 end
274 end)
275 :filter(function(p) return not p.draft or global.mode == "dev" end)
276
270 allItems:sort(page_sort(cat.list_order)) 277 allItems:sort(page_sort(cat.list_order))
271 278
272 return cat_to_list_cat(cat, allItems) 279 return cat_to_list_cat(cat, allItems)
273 end) 280 end)
274 :filter(function(cat) return #cat.items ~= 0 end) 281 :filter(function(cat) return #cat.items ~= 0 end)
282
283 return list
275 end 284 end
276end 285end
277 286
@@ -329,7 +338,7 @@ function process(global, meta)
329 meta.date = meta.last_update 338 meta.date = meta.last_update
330 end 339 end
331 340
332 meta.list = generate_list(meta) 341 meta.list = generate_list(global, meta)
333 342
334 return meta 343 return meta
335end 344end