diff options
author | Volpeon <git@volpeon.ink> | 2021-11-17 17:43:40 +0100 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-11-17 17:43:40 +0100 |
commit | 18321ad1c5c09534e39817d9b75070b5481950bd (patch) | |
tree | 9a1064ac9294be0211533e58bd36fd692aff0888 /scripts | |
parent | Undo preload removal (diff) | |
download | volpeon.ink-18321ad1c5c09534e39817d9b75070b5481950bd.tar.gz volpeon.ink-18321ad1c5c09534e39817d9b75070b5481950bd.tar.bz2 volpeon.ink-18321ad1c5c09534e39817d9b75070b5481950bd.zip |
Improved list, made header sticky, removed git link
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/metadata_filter.lua | 101 |
1 files changed, 63 insertions, 38 deletions
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 5a547ee..5fa7dfc 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua | |||
@@ -9,6 +9,16 @@ function pandoc.List:flatMap(fn) | |||
9 | return result | 9 | return result |
10 | end | 10 | end |
11 | 11 | ||
12 | function pandoc.List:take(n) | ||
13 | if n >= #self then return self end | ||
14 | |||
15 | local result = pandoc.List() | ||
16 | |||
17 | for i = 1, n do result:insert(self[i]) end | ||
18 | |||
19 | return result | ||
20 | end | ||
21 | |||
12 | function format_date(date) | 22 | function format_date(date) |
13 | if not date then return date end | 23 | if not date then return date end |
14 | 24 | ||
@@ -186,6 +196,8 @@ end | |||
186 | function generate_list(meta) | 196 | function generate_list(meta) |
187 | if not meta.pages then return nil end | 197 | if not meta.pages then return nil end |
188 | 198 | ||
199 | local limit = (meta.list_limit and tonumber(pandoc.utils.stringify(meta.list_limit))) or 9999 | ||
200 | |||
189 | if meta.depth == "1" then | 201 | if meta.depth == "1" then |
190 | return meta.pages.all:map(function(p) | 202 | return meta.pages.all:map(function(p) |
191 | return { | 203 | return { |
@@ -200,57 +212,69 @@ function generate_list(meta) | |||
200 | end) | 212 | end) |
201 | elseif meta.depth == "2" then | 213 | elseif meta.depth == "2" then |
202 | return meta.pages.all:map(function(cat) | 214 | return meta.pages.all:map(function(cat) |
215 | local allItems = ((cat.pages and cat.pages.all) or pandoc.List()):map(function(p) | ||
216 | return { | ||
217 | title = p.title, | ||
218 | subtitle = p.subtitle, | ||
219 | date = p.date, | ||
220 | url = p.url, | ||
221 | icon = p.icon or cat.icon, | ||
222 | post_icon = cat.list_post_icon or meta.list_post_icon, | ||
223 | indicator = cat.list_read_indicators, | ||
224 | } | ||
225 | end) | ||
226 | local items = allItems:take(limit) | ||
227 | local omitted = #allItems - #items | ||
228 | |||
203 | return { | 229 | return { |
204 | title = cat.title, | 230 | title = cat.title, |
205 | content = cat.content, | 231 | content = cat.content, |
206 | url = cat.url, | 232 | url = cat.url, |
207 | grid = cat.list_grid, | 233 | grid = cat.list_grid, |
208 | items = ((cat.pages and cat.pages.all) or pandoc.List()):map(function(p) | 234 | items = items, |
209 | return { | 235 | total = tostring(#allItems), |
210 | title = p.title, | 236 | omitted = omitted ~= 0 and tostring(omitted), |
211 | subtitle = p.subtitle, | ||
212 | date = p.date, | ||
213 | url = p.url, | ||
214 | icon = p.icon or cat.icon, | ||
215 | post_icon = cat.list_post_icon or meta.list_post_icon, | ||
216 | indicator = cat.list_read_indicators, | ||
217 | } | ||
218 | end), | ||
219 | } | 237 | } |
220 | end):filter(function(cat) return #cat.items ~= 0 end) | 238 | end):filter(function(cat) return #cat.items ~= 0 end) |
221 | elseif meta.depth == "3" then | 239 | elseif meta.depth == "3" then |
222 | return meta.pages.all:map(function(cat) | 240 | return meta.pages.all:map(function(cat) |
241 | local allItems = (cat.pages and cat.pages.all or pandoc.List()):flatMap(function(c) | ||
242 | if c.pages then | ||
243 | return c.pages.all:map(function(p) | ||
244 | return { | ||
245 | title = p.title, | ||
246 | subtitle = p.subtitle, | ||
247 | category = c.title, | ||
248 | url = p.url, | ||
249 | icon = p.icon or c.icon, | ||
250 | post_icon = c.list_post_icon or cat.list_post_icon, | ||
251 | indicator = c.list_read_indicators, | ||
252 | } | ||
253 | end) | ||
254 | else | ||
255 | local l = pandoc.List() | ||
256 | l:insert({ | ||
257 | title = c.title, | ||
258 | subtitle = c.subtitle, | ||
259 | url = c.url, | ||
260 | icon = c.icon or cat.icon, | ||
261 | post_icon = cat.list_post_icon, | ||
262 | indicator = cat.list_read_indicators, | ||
263 | }) | ||
264 | return l | ||
265 | end | ||
266 | end) | ||
267 | local items = allItems:take(limit) | ||
268 | local omitted = #allItems - #items | ||
269 | |||
223 | return { | 270 | return { |
224 | title = cat.title, | 271 | title = cat.title, |
225 | content = cat.content, | 272 | content = cat.content, |
226 | url = cat.url, | 273 | url = cat.url, |
227 | grid = cat.list_grid, | 274 | grid = cat.list_grid, |
228 | items = (cat.pages and cat.pages.all or pandoc.List()):flatMap(function(c) | 275 | items = items, |
229 | if c.pages then | 276 | total = tostring(#allItems), |
230 | return c.pages.all:map(function(p) | 277 | omitted = omitted ~= 0 and tostring(omitted), |
231 | return { | ||
232 | title = p.title, | ||
233 | subtitle = p.subtitle, | ||
234 | category = c.title, | ||
235 | url = p.url, | ||
236 | icon = p.icon or c.icon, | ||
237 | post_icon = c.list_post_icon or cat.list_post_icon, | ||
238 | indicator = c.list_read_indicators, | ||
239 | } | ||
240 | end) | ||
241 | else | ||
242 | local l = pandoc.List() | ||
243 | l:insert({ | ||
244 | title = c.title, | ||
245 | subtitle = c.subtitle, | ||
246 | url = c.url, | ||
247 | icon = c.icon or cat.icon, | ||
248 | post_icon = cat.list_post_icon, | ||
249 | indicator = cat.list_read_indicators, | ||
250 | }) | ||
251 | return l | ||
252 | end | ||
253 | end), | ||
254 | } | 278 | } |
255 | end):filter(function(cat) return #cat.items ~= 0 end) | 279 | end):filter(function(cat) return #cat.items ~= 0 end) |
256 | end | 280 | end |
@@ -293,7 +317,8 @@ function process(global, parent, meta) | |||
293 | meta.pages = | 317 | meta.pages = |
294 | process_pages(global, { parent = parent, meta = meta }, meta.list_order, meta.pages) | 318 | process_pages(global, { parent = parent, meta = meta }, meta.list_order, meta.pages) |
295 | meta.depth = (meta.pages and find_depth(meta.pages.all)) or "0" | 319 | meta.depth = (meta.pages and find_depth(meta.pages.all)) or "0" |
296 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) | 320 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or |
321 | resolve_layout(meta.depth)) | ||
297 | 322 | ||
298 | if meta.date then | 323 | if meta.date then |
299 | meta.date = format_date(meta.date) | 324 | meta.date = format_date(meta.date) |