summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/metadata_filter.lua81
1 files changed, 48 insertions, 33 deletions
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua
index 895139d..3bea687 100644
--- a/scripts/metadata_filter.lua
+++ b/scripts/metadata_filter.lua
@@ -106,11 +106,18 @@ end
106function process_pages(global, pages_by_id) 106function process_pages(global, pages_by_id)
107 if not pages_by_id then return nil end 107 if not pages_by_id then return nil end
108 108
109 local pages_list = pandoc.List() 109 local pages_all = pandoc.List()
110 110 local pages_asc_title = pandoc.List()
111 for _, page in pairs(pages_by_id) do pages_list:insert(process(global, page)) end 111 local pages_desc_date = pandoc.List()
112
113 for _, page in pairs(pages_by_id) do
114 local p = process(global, page)
115 pages_all:insert(p)
116 pages_asc_title:insert(p)
117 if p.date then pages_desc_date:insert(p) end
118 end
112 119
113 pages_list:sort(function(p1, p2) 120 pages_all:sort(function(p1, p2)
114 if p1.position then 121 if p1.position then
115 if p2.position then 122 if p2.position then
116 return tonumber(p1.position) < tonumber(p2.position) 123 return tonumber(p1.position) < tonumber(p2.position)
@@ -132,36 +139,40 @@ function process_pages(global, pages_by_id)
132 end 139 end
133 end) 140 end)
134 141
135 local pages_by_category = pages_list:filter(function(p) return p.category ~= nil end) 142 pages_desc_date:sort(function(p1, p2)
136 pages_by_category = group_by(pages_by_category, function(p) return p.category.id end, 143 if p1.position then
137 function(data, _, p) 144 if p2.position then
138 if not data then 145 return tonumber(p1.position) < tonumber(p2.position)
139 local l = pandoc.List()
140 l:insert(p)
141 return { name = pandoc.utils.stringify(p.category.name), pages = l }
142 else 146 else
143 data.pages:insert(p) 147 return true
144 end 148 end
145 end) 149 else
146 pages_by_category = table_to_list(pages_by_category, false, 150 return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd
147 function(i1, i2) return i1.name < i2.name end) 151 end
148 152 end)
149 local pages_data = { all = pages_list, by_id = pages_by_id, by_category = pages_by_category }
150
151 return pages_data
152end
153
154function pages_last_update(all_pages)
155 local last_update = format_date("1990-01-01")
156 153
157 for i = 1, #all_pages do 154 pages_asc_title:sort(function(p1, p2)
158 local page = all_pages[i] 155 if p1.position then
159 if page.last_update and page.last_update.yyyy_mm_dd > last_update.yyyy_mm_dd then 156 if p2.position then
160 last_update = page.last_update 157 return tonumber(p1.position) < tonumber(p2.position)
158 else
159 return true
160 end
161 elseif p2.position then
162 return false
163 else
164 return p1.title < p2.title
161 end 165 end
162 end 166 end)
167
168 local pages_data = {
169 all = pages_all,
170 desc_date = pages_desc_date,
171 asc_title = pages_asc_title,
172 by_id = pages_by_id,
173 }
163 174
164 return last_update 175 return pages_data
165end 176end
166 177
167local titlecase_exceptions = pandoc.List({ 178local titlecase_exceptions = pandoc.List({
@@ -208,20 +219,24 @@ function process(global, meta)
208 meta.preview = resolve_url(global.site.url, global.file_out, meta.preview) 219 meta.preview = resolve_url(global.site.url, global.file_out, meta.preview)
209 end 220 end
210 221
211 if meta.date then meta.date = format_date(meta.date) end
212
213 if meta.menus and meta.menus.main then 222 if meta.menus and meta.menus.main then
214 meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) 223 meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main)
215 end 224 end
216 225
217 meta.pages = process_pages(global, meta.pages) 226 meta.pages = process_pages(global, meta.pages)
218 227
228 if meta.date then
229 meta.date = format_date(meta.date)
230 elseif meta.pages and #meta.pages.desc_date ~= 0 then
231 meta.date = meta.pages.desc_date[1].date
232 end
233
219 if meta.last_update then 234 if meta.last_update then
220 meta.last_update = format_date(meta.last_update) 235 meta.last_update = format_date(meta.last_update)
236 elseif meta.pages and #meta.pages.desc_date ~= 0 then
237 meta.last_update = meta.pages.desc_date[1].last_update
221 elseif meta.date then 238 elseif meta.date then
222 meta.last_update = meta.date 239 meta.last_update = meta.date
223 elseif meta.pages then
224 meta.last_update = pages_last_update(meta.pages.all)
225 end 240 end
226 241
227 return meta 242 return meta