summaryrefslogtreecommitdiffstats
path: root/scripts/metadata.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/metadata.lua')
-rw-r--r--scripts/metadata.lua39
1 files changed, 30 insertions, 9 deletions
diff --git a/scripts/metadata.lua b/scripts/metadata.lua
index afd0ca5..5d372fc 100644
--- a/scripts/metadata.lua
+++ b/scripts/metadata.lua
@@ -71,13 +71,11 @@ function prep_menu(active_id, main_menu)
71 return { items = items, active = active_item } 71 return { items = items, active = active_item }
72end 72end
73 73
74function process_pages(global, build, meta) 74function process_pages(meta)
75 local pages_all = pandoc.List() 75 local pages_all = pandoc.List()
76 local pages_date_desc = pandoc.List() 76 local pages_date_desc = pandoc.List()
77 77
78 for id, p in pairs(meta.pages) do 78 for id, p in pairs(meta.pages) do
79 process(global, build, p, meta)
80
81 if not p.unlisted then 79 if not p.unlisted then
82 pages_all:insert(id) 80 pages_all:insert(id)
83 if p.last_update then pages_date_desc:insert(id) end 81 if p.last_update then pages_date_desc:insert(id) end
@@ -86,8 +84,14 @@ function process_pages(global, build, meta)
86 84
87 pages_all:sort(sort.page_sort(meta.list_order, meta.pages)) 85 pages_all:sort(sort.page_sort(meta.list_order, meta.pages))
88 pages_date_desc:sort(sort.page_sort("date_desc", meta.pages)) 86 pages_date_desc:sort(sort.page_sort("date_desc", meta.pages))
87 local pages_random = pages_all:clone():shuffle()
89 88
90 meta.pages = { all = pages_all, date_desc = pages_date_desc, by_id = meta.pages } 89 meta.pages = {
90 all = pages_all,
91 date_desc = pages_date_desc,
92 random = pages_random,
93 by_id = meta.pages
94 }
91end 95end
92 96
93function find_depth(meta) 97function find_depth(meta)
@@ -126,7 +130,7 @@ function resolve_dates(meta)
126 meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd 130 meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd
127end 131end
128 132
129function process_base(build, meta, parent) 133function process_base(build, meta)
130 meta.namespace = prep_namespace(meta.namespace) 134 meta.namespace = prep_namespace(meta.namespace)
131 meta.file_out = utils.stringify(meta.file_out) 135 meta.file_out = utils.stringify(meta.file_out)
132 meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") 136 meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev")
@@ -140,16 +144,33 @@ function process_base(build, meta, parent)
140 meta.position = meta.position and tonumber(utils.stringify(meta.position)) 144 meta.position = meta.position and tonumber(utils.stringify(meta.position))
141 meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. utils.stringify(meta.thumbnail), meta.file_out) 145 meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. utils.stringify(meta.thumbnail), meta.file_out)
142 meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) 146 meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth))
143 meta.show_date = parent and parent.list_order == "date_desc" 147
148 meta.description = (meta.description and pandoc.MetaBlocks(pandoc.Para(meta.description))) or
149 (not meta.no_description and meta.content)
150 meta.show_date = meta.parent and meta.parent.list_order == "date_desc"
151 meta.category = meta.parent and meta.parent.title
152 meta.icon = meta.icon or (meta.parent and meta.parent.icon)
153 meta.post_icon = meta.post_icon or (meta.parent and meta.parent.list_post_icon) or
154 (meta.parent and meta.parent.parent and meta.parent.parent.list_post_icon)
155 meta.indicator = meta.parent and meta.parent.list_read_indicators
144end 156end
145 157
146function process(global, build, meta, parent) 158function process(global, build, meta)
147 process_base(build, meta, parent) 159 process_base(build, meta)
148 process_pages(global, build, meta) 160
161 for _, p in pairs(meta.pages) do
162 p.parent = meta
163 process(global, build, p)
164 p.parent = nil
165 end
166
167 process_pages(meta)
149 resolve_dates(meta) 168 resolve_dates(meta)
150end 169end
151 170
152function Meta(meta) 171function Meta(meta)
172 math.randomseed(os.time())
173
153 local build = {} 174 local build = {}
154 175
155 for key, value in pairs(meta) do 176 for key, value in pairs(meta) do