diff options
author | Volpeon <git@volpeon.ink> | 2021-05-26 08:54:19 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-05-26 08:54:19 +0200 |
commit | e3240a57eef6bf0afa193ae83ecd8c5cf627c72f (patch) | |
tree | f25393ecfb6f06de92715dc95aa1d0aeb74c4d30 /scripts | |
parent | Hide some profiles from home page (diff) | |
download | volpeon.ink-e3240a57eef6bf0afa193ae83ecd8c5cf627c72f.tar.gz volpeon.ink-e3240a57eef6bf0afa193ae83ecd8c5cf627c72f.tar.bz2 volpeon.ink-e3240a57eef6bf0afa193ae83ecd8c5cf627c72f.zip |
Category list improvements, generate ATOM feeds
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/metadata_filter.lua | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 000fda6..ebbd6d4 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua | |||
@@ -5,7 +5,7 @@ function format_date(date) | |||
5 | local year, month, day = date:match("(%d%d%d%d)-(%d%d)-(%d%d)") | 5 | local year, month, day = date:match("(%d%d%d%d)-(%d%d)-(%d%d)") |
6 | if not year then return nil end | 6 | if not year then return nil end |
7 | 7 | ||
8 | local time = os.time({year = tonumber(year), month = tonumber(month), day = tonumber(day)}) | 8 | local time = os.time({ year = tonumber(year), month = tonumber(month), day = tonumber(day) }) |
9 | return { | 9 | return { |
10 | yyyy_mm_dd = os.date("%F", time), | 10 | yyyy_mm_dd = os.date("%F", time), |
11 | yyyy = os.date("%Y", time), | 11 | yyyy = os.date("%Y", time), |
@@ -21,7 +21,7 @@ function table_to_list(t, kv, cmp) | |||
21 | local l = pandoc.List() | 21 | local l = pandoc.List() |
22 | 22 | ||
23 | if kv then | 23 | if kv then |
24 | for key, value in pairs(t) do l:insert({key = key, value = value}) end | 24 | for key, value in pairs(t) do l:insert({ key = key, value = value }) end |
25 | else | 25 | else |
26 | for _, value in pairs(t) do l:insert(value) end | 26 | for _, value in pairs(t) do l:insert(value) end |
27 | end | 27 | end |
@@ -34,7 +34,7 @@ end | |||
34 | function group_by(l, field, insert) | 34 | function group_by(l, field, insert) |
35 | insert = insert or function(group, _, item) | 35 | insert = insert or function(group, _, item) |
36 | if not group then | 36 | if not group then |
37 | group = l:new({item}) | 37 | group = l:new({ item }) |
38 | return group | 38 | return group |
39 | end | 39 | end |
40 | group:insert(item) | 40 | group:insert(item) |
@@ -101,13 +101,13 @@ function resolve_url(site_url, ref_file, target_file) | |||
101 | local abs = target_file | 101 | local abs = target_file |
102 | local rel = relative_to(ref_base_dir, abs):gsub("/index%.html$", "/") | 102 | local rel = relative_to(ref_base_dir, abs):gsub("/index%.html$", "/") |
103 | 103 | ||
104 | return {abs = abs, rel = rel, full = (site_url .. abs)} | 104 | return { abs = abs, rel = rel, full = (site_url .. abs) } |
105 | end | 105 | end |
106 | 106 | ||
107 | function resolve_layout(layout) | 107 | function resolve_layout(layout) |
108 | if layout then | 108 | if layout then |
109 | layout = pandoc.utils.stringify(layout) | 109 | layout = pandoc.utils.stringify(layout) |
110 | return {id = layout, ["is_" .. layout] = true} | 110 | return { id = layout, ["is_" .. layout] = true } |
111 | end | 111 | end |
112 | end | 112 | end |
113 | 113 | ||
@@ -117,7 +117,7 @@ function resolve_namespace(namespace) | |||
117 | local root = "index" | 117 | local root = "index" |
118 | if namespace ~= "" then root = namespace:gsub("^/([^/]*).*$", "%1") end | 118 | if namespace ~= "" then root = namespace:gsub("^/([^/]*).*$", "%1") end |
119 | 119 | ||
120 | return {root = {id = root, ["is_" .. root] = true}, full = namespace} | 120 | return { root = { id = root, ["is_" .. root] = true }, full = namespace } |
121 | end | 121 | end |
122 | 122 | ||
123 | function prep_menu(active_id, main_menu) | 123 | function prep_menu(active_id, main_menu) |
@@ -137,17 +137,22 @@ function prep_menu(active_id, main_menu) | |||
137 | end | 137 | end |
138 | 138 | ||
139 | function process_pages(global, pages_by_id) | 139 | function process_pages(global, pages_by_id) |
140 | if not pages_by_id then pages_by_id = {} end | 140 | if not pages_by_id then return nil end |
141 | 141 | ||
142 | local pages_list = pandoc.List() | 142 | local pages_list = pandoc.List() |
143 | 143 | ||
144 | for _, page in pairs(pages_by_id) do | 144 | for _, page in pairs(pages_by_id) do pages_list:insert(process(global, page)) end |
145 | page = process(global, page) | ||
146 | pages_list:insert(page) | ||
147 | end | ||
148 | 145 | ||
149 | pages_list:sort(function(p1, p2) | 146 | pages_list:sort(function(p1, p2) |
150 | if p1.date then | 147 | if p1.position then |
148 | if p2.position then | ||
149 | return p1.position < p2.position | ||
150 | else | ||
151 | return true | ||
152 | end | ||
153 | elseif p2.position then | ||
154 | return false | ||
155 | elseif p1.date then | ||
151 | if p2.date then | 156 | if p2.date then |
152 | return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd | 157 | return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd |
153 | else | 158 | else |
@@ -166,7 +171,7 @@ function process_pages(global, pages_by_id) | |||
166 | if not data then | 171 | if not data then |
167 | local l = pandoc.List() | 172 | local l = pandoc.List() |
168 | l:insert(p) | 173 | l:insert(p) |
169 | return {name = pandoc.utils.stringify(p.category.name), pages = l} | 174 | return { name = pandoc.utils.stringify(p.category.name), pages = l } |
170 | else | 175 | else |
171 | data.pages:insert(p) | 176 | data.pages:insert(p) |
172 | end | 177 | end |
@@ -174,11 +179,24 @@ function process_pages(global, pages_by_id) | |||
174 | pages_by_category = table_to_list(pages_by_category, false, | 179 | pages_by_category = table_to_list(pages_by_category, false, |
175 | function(i1, i2) return i1.name < i2.name end) | 180 | function(i1, i2) return i1.name < i2.name end) |
176 | 181 | ||
177 | local pages_data = {all = pages_list, by_id = pages_by_id, by_category = pages_by_category} | 182 | local pages_data = { all = pages_list, by_id = pages_by_id, by_category = pages_by_category } |
178 | 183 | ||
179 | return pages_data | 184 | return pages_data |
180 | end | 185 | end |
181 | 186 | ||
187 | function pages_last_update(all_pages) | ||
188 | local last_update = format_date("1990-01-01") | ||
189 | |||
190 | for i = 1, #all_pages do | ||
191 | local page = all_pages[i] | ||
192 | if page.last_update and page.last_update.yyyy_mm_dd > last_update.yyyy_mm_dd then | ||
193 | last_update = page.last_update | ||
194 | end | ||
195 | end | ||
196 | |||
197 | return last_update | ||
198 | end | ||
199 | |||
182 | function process(global, meta) | 200 | function process(global, meta) |
183 | meta.namespace = resolve_namespace(meta.namespace) | 201 | meta.namespace = resolve_namespace(meta.namespace) |
184 | meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") | 202 | meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") |
@@ -186,6 +204,22 @@ function process(global, meta) | |||
186 | meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) | 204 | meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) |
187 | meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" | 205 | meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" |
188 | 206 | ||
207 | if meta.position then meta.position = pandoc.utils.stringify(meta.position) end | ||
208 | |||
209 | if meta.create_feed then | ||
210 | if meta.file_out:match(".html$") then | ||
211 | meta.feed = { | ||
212 | url = resolve_url(global.site.url, global.file_out, | ||
213 | meta.file_out:gsub(".html$", ".xml")), | ||
214 | } | ||
215 | else | ||
216 | meta.page = { | ||
217 | url = resolve_url(global.site.url, global.file_out, | ||
218 | meta.file_out:gsub(".xml$", ".html")), | ||
219 | } | ||
220 | end | ||
221 | end | ||
222 | |||
189 | if meta.preview then | 223 | if meta.preview then |
190 | meta.preview = make_absolute(pandoc.utils.stringify(meta.preview), meta.file_out) | 224 | meta.preview = make_absolute(pandoc.utils.stringify(meta.preview), meta.file_out) |
191 | meta.preview = resolve_url(global.site.url, global.file_out, meta.preview) | 225 | meta.preview = resolve_url(global.site.url, global.file_out, meta.preview) |
@@ -193,18 +227,20 @@ function process(global, meta) | |||
193 | 227 | ||
194 | if meta.date then meta.date = format_date(meta.date) end | 228 | if meta.date then meta.date = format_date(meta.date) end |
195 | 229 | ||
196 | if meta.last_update then | ||
197 | meta.last_update = format_date(meta.last_update) | ||
198 | else | ||
199 | meta.last_update = meta.date | ||
200 | end | ||
201 | |||
202 | if meta.menus and meta.menus.main then | 230 | if meta.menus and meta.menus.main then |
203 | meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) | 231 | meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) |
204 | end | 232 | end |
205 | 233 | ||
206 | meta.pages = process_pages(global, meta.pages) | 234 | meta.pages = process_pages(global, meta.pages) |
207 | 235 | ||
236 | if meta.last_update then | ||
237 | meta.last_update = format_date(meta.last_update) | ||
238 | elseif meta.date then | ||
239 | meta.last_update = meta.date | ||
240 | elseif meta.pages then | ||
241 | meta.last_update = pages_last_update(meta.pages.all) | ||
242 | end | ||
243 | |||
208 | return meta | 244 | return meta |
209 | end | 245 | end |
210 | 246 | ||