summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/metadata_filter.lua96
1 files changed, 88 insertions, 8 deletions
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua
index ebd69f1..b16d472 100644
--- a/scripts/metadata_filter.lua
+++ b/scripts/metadata_filter.lua
@@ -1,5 +1,14 @@
1local path = require 'pandoc.path' 1local path = require 'pandoc.path'
2 2
3function pandoc.List:flatMap(fn)
4 local mapped = self:map(fn)
5 local result = pandoc.List()
6
7 for i = 1, #mapped do result:extend(mapped[i]) end
8
9 return result
10end
11
3function format_date(date) 12function format_date(date)
4 if not date then return date end 13 if not date then return date end
5 14
@@ -49,14 +58,12 @@ function resolve_url(site_url, ref_file, target_file)
49end 58end
50 59
51function resolve_layout(depth) 60function resolve_layout(depth)
52 local layout = "deep_categorized_list" 61 local layout = "categorized_list"
53 62
54 if depth == "0" then 63 if depth == "0" then
55 layout = "page" 64 layout = "page"
56 elseif depth == "1" then 65 elseif depth == "1" then
57 layout = "list" 66 layout = "list"
58 elseif depth == "2" then
59 layout = "categorized_list"
60 end 67 end
61 68
62 return layout 69 return layout
@@ -91,14 +98,14 @@ function prep_menu(active_id, main_menu)
91 return { items = items, active = active_item } 98 return { items = items, active = active_item }
92end 99end
93 100
94function process_pages(global, order, pages_by_id) 101function process_pages(global, parent, order, pages_by_id)
95 if not pages_by_id then return nil end 102 if not pages_by_id then return nil end
96 103
97 local pages_all = pandoc.List() 104 local pages_all = pandoc.List()
98 local pages_date_desc = pandoc.List() 105 local pages_date_desc = pandoc.List()
99 106
100 for _, page in pairs(pages_by_id) do 107 for _, page in pairs(pages_by_id) do
101 local p = process(global, page) 108 local p = process(global, parent, page)
102 if not p.unlisted then 109 if not p.unlisted then
103 pages_all:insert(p) 110 pages_all:insert(p)
104 if p.date then pages_date_desc:insert(p) end 111 if p.date then pages_date_desc:insert(p) end
@@ -176,7 +183,77 @@ function find_depth(pages)
176 return tostring(depth) 183 return tostring(depth)
177end 184end
178 185
179function process(global, meta) 186function generate_list(meta)
187 if meta.depth == "1" then
188 return meta.pages.all:map(function(p)
189 return {
190 title = p.title,
191 subtitle = p.subtitle,
192 date = p.date,
193 url = p.url,
194 icon = p.icon or meta.icon,
195 post_icon = meta.list_post_icon,
196 indicator = meta.list_read_indicators,
197 }
198 end)
199 elseif meta.depth == "2" then
200 return meta.pages.all:map(function(cat)
201 return {
202 title = cat.title,
203 content = pandoc.utils.stringify(cat.content),
204 url = cat.url,
205 grid = cat.list_grid,
206 items = cat.pages.all:map(function(p)
207 return {
208 title = p.title,
209 subtitle = p.subtitle,
210 date = p.date,
211 url = p.url,
212 icon = p.icon or cat.icon,
213 post_icon = cat.list_post_icon or meta.list_post_icon,
214 indicator = cat.list_read_indicators,
215 }
216 end),
217 }
218 end)
219 elseif meta.depth == "3" then
220 return meta.pages.all:map(function(cat)
221 return {
222 title = cat.title,
223 content = pandoc.utils.stringify(cat.content),
224 url = cat.url,
225 grid = cat.list_grid,
226 items = cat.pages.all:flatMap(function(c)
227 if c.pages then
228 return c.pages.all:map(function(p)
229 return {
230 title = p.title,
231 subtitle = p.subtitle or c.title,
232 url = p.url,
233 icon = p.icon or c.icon,
234 post_icon = c.list_post_icon or cat.list_post_icon,
235 indicator = c.list_read_indicators,
236 }
237 end)
238 else
239 local l = pandoc.List()
240 l:insert({
241 title = c.title,
242 subtitle = c.subtitle,
243 url = c.url,
244 icon = c.icon or meta.icon,
245 post_icon = meta.list_post_icon,
246 indicator = meta.list_read_indicators,
247 })
248 return l
249 end
250 end),
251 }
252 end)
253 end
254end
255
256function process(global, parent, meta)
180 meta.namespace = resolve_namespace(meta.namespace) 257 meta.namespace = resolve_namespace(meta.namespace)
181 meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") 258 meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "")
182 meta.url = meta.url and pandoc.utils.stringify(meta.url) 259 meta.url = meta.url and pandoc.utils.stringify(meta.url)
@@ -209,7 +286,8 @@ function process(global, meta)
209 meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) 286 meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main)
210 end 287 end
211 288
212 meta.pages = process_pages(global, meta.list_order, meta.pages) 289 meta.pages =
290 process_pages(global, { parent = parent, meta = meta }, meta.list_order, meta.pages)
213 meta.depth = (meta.pages and find_depth(meta.pages.all)) or "0" 291 meta.depth = (meta.pages and find_depth(meta.pages.all)) or "0"
214 meta.layout = prep_layout(meta.layout or resolve_layout(meta.depth)) 292 meta.layout = prep_layout(meta.layout or resolve_layout(meta.depth))
215 293
@@ -227,11 +305,13 @@ function process(global, meta)
227 meta.last_update = meta.date 305 meta.last_update = meta.date
228 end 306 end
229 307
308 meta.list = generate_list(meta)
309
230 return meta 310 return meta
231end 311end
232 312
233function Meta(meta) 313function Meta(meta)
234 meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") 314 meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "")
235 315
236 return process(meta, meta) 316 return process(meta, nil, meta)
237end 317end