diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/metadata_filter.lua | 57 |
1 files changed, 19 insertions, 38 deletions
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index daad940..7039a2c 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua | |||
@@ -102,18 +102,16 @@ function prep_menu(active_id, main_menu) | |||
102 | return { items = items, active = active_item } | 102 | return { items = items, active = active_item } |
103 | end | 103 | end |
104 | 104 | ||
105 | function process_pages(global, pages_by_id) | 105 | function process_pages(global, order, pages_by_id) |
106 | if not pages_by_id then return nil end | 106 | if not pages_by_id then return nil end |
107 | 107 | ||
108 | local pages_all = pandoc.List() | 108 | local pages_all = pandoc.List() |
109 | local pages_asc_title = pandoc.List() | 109 | local pages_date_desc = pandoc.List() |
110 | local pages_desc_date = pandoc.List() | ||
111 | 110 | ||
112 | for _, page in pairs(pages_by_id) do | 111 | for _, page in pairs(pages_by_id) do |
113 | local p = process(global, page) | 112 | local p = process(global, page) |
114 | pages_all:insert(p) | 113 | pages_all:insert(p) |
115 | pages_asc_title:insert(p) | 114 | if p.date then pages_date_desc:insert(p) end |
116 | if p.date then pages_desc_date:insert(p) end | ||
117 | end | 115 | end |
118 | 116 | ||
119 | pages_all:sort(function(p1, p2) | 117 | pages_all:sort(function(p1, p2) |
@@ -125,20 +123,22 @@ function process_pages(global, pages_by_id) | |||
125 | end | 123 | end |
126 | elseif p2.position then | 124 | elseif p2.position then |
127 | return false | 125 | return false |
128 | elseif p1.date then | 126 | elseif order == "date_desc" then |
129 | if p2.date then | 127 | if p1.date then |
130 | return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd | 128 | if p2.date then |
129 | return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd | ||
130 | else | ||
131 | return true | ||
132 | end | ||
131 | else | 133 | else |
132 | return true | 134 | return false |
133 | end | 135 | end |
134 | elseif p2.date then | ||
135 | return false | ||
136 | else | 136 | else |
137 | return p1.title < p2.title | 137 | return p1.title < p2.title |
138 | end | 138 | end |
139 | end) | 139 | end) |
140 | 140 | ||
141 | pages_desc_date:sort(function(p1, p2) | 141 | pages_date_desc:sort(function(p1, p2) |
142 | if p1.position then | 142 | if p1.position then |
143 | if p2.position then | 143 | if p2.position then |
144 | return tonumber(p1.position) < tonumber(p2.position) | 144 | return tonumber(p1.position) < tonumber(p2.position) |
@@ -150,26 +150,7 @@ function process_pages(global, pages_by_id) | |||
150 | end | 150 | end |
151 | end) | 151 | end) |
152 | 152 | ||
153 | pages_asc_title:sort(function(p1, p2) | 153 | local pages_data = { all = pages_all, date_desc = pages_date_desc, by_id = pages_by_id } |
154 | if p1.position then | ||
155 | if p2.position then | ||
156 | return tonumber(p1.position) < tonumber(p2.position) | ||
157 | else | ||
158 | return true | ||
159 | end | ||
160 | elseif p2.position then | ||
161 | return false | ||
162 | else | ||
163 | return p1.title < p2.title | ||
164 | end | ||
165 | end) | ||
166 | |||
167 | local pages_data = { | ||
168 | all = pages_all, | ||
169 | desc_date = pages_desc_date, | ||
170 | asc_title = pages_asc_title, | ||
171 | by_id = pages_by_id, | ||
172 | } | ||
173 | 154 | ||
174 | return pages_data | 155 | return pages_data |
175 | end | 156 | end |
@@ -196,7 +177,7 @@ function process(global, meta) | |||
196 | meta.layout = resolve_layout(meta.layout) | 177 | meta.layout = resolve_layout(meta.layout) |
197 | meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) | 178 | meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) |
198 | meta.title = (meta.title and titlecase(pandoc.utils.stringify(meta.title))) or "" | 179 | meta.title = (meta.title and titlecase(pandoc.utils.stringify(meta.title))) or "" |
199 | 180 | if meta.list_order then meta.list_order = pandoc.utils.stringify(meta.list_order) end | |
200 | if meta.position then meta.position = pandoc.utils.stringify(meta.position) end | 181 | if meta.position then meta.position = pandoc.utils.stringify(meta.position) end |
201 | 182 | ||
202 | if meta.create_feed then | 183 | if meta.create_feed then |
@@ -222,18 +203,18 @@ function process(global, meta) | |||
222 | meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) | 203 | meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) |
223 | end | 204 | end |
224 | 205 | ||
225 | meta.pages = process_pages(global, meta.pages) | 206 | meta.pages = process_pages(global, meta.list_order, meta.pages) |
226 | 207 | ||
227 | if meta.date then | 208 | if meta.date then |
228 | meta.date = format_date(meta.date) | 209 | meta.date = format_date(meta.date) |
229 | elseif meta.pages and #meta.pages.desc_date ~= 0 then | 210 | elseif meta.pages and #meta.pages.date_desc ~= 0 then |
230 | meta.date = meta.pages.desc_date[1].date | 211 | meta.date = meta.pages.date_desc[1].date |
231 | end | 212 | end |
232 | 213 | ||
233 | if meta.last_update then | 214 | if meta.last_update then |
234 | meta.last_update = format_date(meta.last_update) | 215 | meta.last_update = format_date(meta.last_update) |
235 | elseif meta.pages and #meta.pages.desc_date ~= 0 then | 216 | elseif meta.pages and #meta.pages.date_desc ~= 0 then |
236 | meta.last_update = meta.pages.desc_date[1].last_update | 217 | meta.last_update = meta.pages.date_desc[1].last_update |
237 | elseif meta.date then | 218 | elseif meta.date then |
238 | meta.last_update = meta.date | 219 | meta.last_update = meta.date |
239 | end | 220 | end |