diff options
author | Volpeon <git@volpeon.ink> | 2022-07-29 07:59:41 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2022-07-29 07:59:41 +0200 |
commit | 8a3b78c8e07dea97d8b51d1ec6ff2f5ff814f95a (patch) | |
tree | 33bc915a1fbcfc3818b88240f7583e8a4876d2b6 | |
parent | Improved draft badge (diff) | |
download | volpeon.ink-8a3b78c8e07dea97d8b51d1ec6ff2f5ff814f95a.tar.gz volpeon.ink-8a3b78c8e07dea97d8b51d1ec6ff2f5ff814f95a.tar.bz2 volpeon.ink-8a3b78c8e07dea97d8b51d1ec6ff2f5ff814f95a.zip |
Better depth calculation
-rw-r--r-- | content/notebook/pages/index.md | 1 | ||||
-rw-r--r-- | scripts/metadata.lua | 24 |
2 files changed, 17 insertions, 8 deletions
diff --git a/content/notebook/pages/index.md b/content/notebook/pages/index.md index 1c8fbc5..b32e28a 100644 --- a/content/notebook/pages/index.md +++ b/content/notebook/pages/index.md | |||
@@ -1,6 +1,5 @@ | |||
1 | --- | 1 | --- |
2 | title: Pages | 2 | title: Pages |
3 | depth: 1 | ||
4 | position: 1 | 3 | position: 1 |
5 | list_read_indicators: true | 4 | list_read_indicators: true |
6 | feed: true | 5 | feed: true |
diff --git a/scripts/metadata.lua b/scripts/metadata.lua index a32ee29..27854b9 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua | |||
@@ -165,16 +165,26 @@ function process_pages(global, order, pages_by_id) | |||
165 | return { 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 | end | 166 | end |
167 | 167 | ||
168 | function find_depth(pages) | 168 | function find_depth(meta) |
169 | if meta.depth then | ||
170 | meta.depth = tonumber(meta.depth) | ||
171 | end | ||
172 | |||
169 | local depth = 0 | 173 | local depth = 0 |
170 | 174 | ||
171 | for i = 1, #pages.all do | 175 | if meta.pages then |
172 | local p = pages.all[i] | 176 | for _, page in pairs(meta.pages) do |
173 | local d = p.depth + 1 | 177 | local p = find_depth(page) |
174 | if d > depth then depth = d end | 178 | if not p.unlisted then |
179 | local d = p.depth + 1 | ||
180 | if d > depth then depth = d end | ||
181 | end | ||
182 | end | ||
175 | end | 183 | end |
176 | 184 | ||
177 | return depth | 185 | meta.depth = depth |
186 | |||
187 | return meta | ||
178 | end | 188 | end |
179 | 189 | ||
180 | function d1_page_to_list_item(meta, p) | 190 | function d1_page_to_list_item(meta, p) |
@@ -314,7 +324,6 @@ function process(global, meta) | |||
314 | end | 324 | end |
315 | 325 | ||
316 | meta.pages = process_pages(global, meta.list_order, meta.pages) | 326 | meta.pages = process_pages(global, meta.list_order, meta.pages) |
317 | meta.depth = meta.depth and tonumber(pandoc.utils.stringify(meta.depth)) or find_depth(meta.pages) | ||
318 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) | 327 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) |
319 | 328 | ||
320 | if meta.last_update then | 329 | if meta.last_update then |
@@ -339,5 +348,6 @@ end | |||
339 | function Meta(meta) | 348 | function Meta(meta) |
340 | meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") | 349 | meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") |
341 | 350 | ||
351 | find_depth(meta) | ||
342 | return process(meta, meta) | 352 | return process(meta, meta) |
343 | end | 353 | end |