diff options
author | Volpeon <git@volpeon.ink> | 2022-08-04 21:27:32 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2022-08-04 21:27:32 +0200 |
commit | 9acab4200ad454a030edefd0f41e39b3e4936c84 (patch) | |
tree | e8b4aed55722827a59deeef868f36f8164bd804e /scripts/page.lua | |
parent | Update (diff) | |
download | volpeon.ink-9acab4200ad454a030edefd0f41e39b3e4936c84.tar.gz volpeon.ink-9acab4200ad454a030edefd0f41e39b3e4936c84.tar.bz2 volpeon.ink-9acab4200ad454a030edefd0f41e39b3e4936c84.zip |
Improved metadata processing
Diffstat (limited to 'scripts/page.lua')
-rw-r--r-- | scripts/page.lua | 181 |
1 files changed, 94 insertions, 87 deletions
diff --git a/scripts/page.lua b/scripts/page.lua index 417e4a0..fd12230 100644 --- a/scripts/page.lua +++ b/scripts/page.lua | |||
@@ -35,93 +35,60 @@ function prep_menu(namespace, main_menu) | |||
35 | return { items = items, active = active_item } | 35 | return { items = items, active = active_item } |
36 | end | 36 | end |
37 | 37 | ||
38 | function process_pages(global, build, meta) | 38 | function d1_page_to_list_item(meta) |
39 | for _, p in pairs(meta.pages.by_id) do | ||
40 | process_pages(global, build, p) | ||
41 | end | ||
42 | |||
43 | meta.pages = { | ||
44 | all = meta.pages.all:map(function (ref) return meta.pages.by_id[utils.stringify(ref)] end), | ||
45 | date_desc = meta.pages.date_desc:map(function (ref) return meta.pages.by_id[utils.stringify(ref)] end), | ||
46 | by_id = meta.pages.by_id | ||
47 | } | ||
48 | end | ||
49 | |||
50 | function resolve_urls(global, build, meta) | ||
51 | meta.url = resolve_url(global.site.url, build.file_out, meta.url) | ||
52 | |||
53 | if meta.feed then | ||
54 | if meta.file_out:match(".html$") then | ||
55 | meta.feed = { | ||
56 | url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")), | ||
57 | } | ||
58 | else | ||
59 | meta.page = { | ||
60 | url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")), | ||
61 | } | ||
62 | end | ||
63 | end | ||
64 | |||
65 | if meta.thumbnail then | ||
66 | meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) | ||
67 | end | ||
68 | end | ||
69 | |||
70 | function d1_page_to_list_item(meta, p) | ||
71 | return { | 39 | return { |
72 | title = p.title, | 40 | title = meta.title, |
73 | subtitle = p.subtitle, | 41 | subtitle = meta.subtitle, |
74 | date = p.date, | 42 | date = meta.date, |
75 | last_update = p.last_update, | 43 | last_update = meta.last_update, |
76 | show_date = p.show_date, | 44 | show_date = meta.show_date, |
77 | schema_type = p.schema_type, | 45 | schema_type = meta.schema_type, |
78 | draft = p.draft, | 46 | draft = meta.draft, |
79 | position = p.position, | 47 | position = meta.position, |
80 | url = p.url, | 48 | url = meta.url, |
81 | rel = p.rel, | 49 | rel = meta.rel, |
82 | slug = p.slug, | 50 | slug = meta.slug, |
83 | thumbnail = p.thumbnail, | 51 | thumbnail = meta.thumbnail, |
84 | icon = p.icon or meta.icon, | 52 | icon = meta.icon, |
85 | post_icon = p.post_icon or meta.list_post_icon, | 53 | post_icon = meta.post_icon, |
86 | indicator = meta.list_read_indicators, | 54 | indicator = meta.indicator, |
87 | } | 55 | } |
88 | end | 56 | end |
89 | 57 | ||
90 | function d2_page_to_list_item(meta, cat, p, set_cat_title) | 58 | function d2_page_to_list_item(meta, with_category) |
91 | return { | 59 | return { |
92 | title = p.title, | 60 | title = meta.title, |
93 | subtitle = p.subtitle, | 61 | subtitle = meta.subtitle, |
94 | category = set_cat_title and cat.title, | 62 | category = with_category and meta.category, |
95 | date = p.date, | 63 | date = meta.date, |
96 | last_update = p.last_update, | 64 | last_update = meta.last_update, |
97 | show_date = p.show_date, | 65 | show_date = meta.show_date, |
98 | schema_type = p.schema_type, | 66 | schema_type = meta.schema_type, |
99 | draft = p.draft, | 67 | draft = meta.draft, |
100 | position = p.position, | 68 | position = meta.position, |
101 | url = p.url, | 69 | url = meta.url, |
102 | rel = p.rel, | 70 | rel = meta.rel, |
103 | slug = p.slug, | 71 | slug = meta.slug, |
104 | thumbnail = p.thumbnail, | 72 | thumbnail = meta.thumbnail, |
105 | icon = p.icon or cat.icon, | 73 | icon = meta.icon, |
106 | post_icon = p.post_icon or cat.list_post_icon or meta.list_post_icon, | 74 | post_icon = meta.post_icon, |
107 | indicator = cat.list_read_indicators, | 75 | indicator = meta.indicator, |
108 | } | 76 | } |
109 | end | 77 | end |
110 | 78 | ||
111 | function cat_to_list_cat(cat, allItems) | 79 | function cat_to_list_cat(meta, allItems) |
112 | local limit = cat.list_limit or 9999 | 80 | local limit = meta.list_limit or 9999 |
113 | local items = allItems:take(limit) | 81 | local items = allItems:take(limit) |
114 | local omitted = #allItems - #items | 82 | local omitted = #allItems - #items |
115 | 83 | ||
116 | return { | 84 | return { |
117 | title = cat.title, | 85 | title = meta.title, |
118 | description = (cat.description and pandoc.MetaBlocks(pandoc.Para(cat.description))) or | 86 | description = meta.description, |
119 | (not cat.no_description and cat.content), | 87 | last_update = meta.last_update, |
120 | last_update = cat.last_update, | 88 | schema_type = meta.schema_type, |
121 | schema_type = cat.schema_type, | 89 | url = meta.url, |
122 | url = cat.url, | 90 | slug = meta.slug, |
123 | slug = cat.slug, | 91 | layout = meta.list_layout, |
124 | layout = cat.list_layout, | ||
125 | items = items, | 92 | items = items, |
126 | total = tostring(#allItems), | 93 | total = tostring(#allItems), |
127 | omitted = omitted ~= 0 and tostring(omitted), | 94 | omitted = omitted ~= 0 and tostring(omitted), |
@@ -132,13 +99,13 @@ function generate_list(meta) | |||
132 | if meta.depth < 1 then return pandoc.List() end | 99 | if meta.depth < 1 then return pandoc.List() end |
133 | 100 | ||
134 | if meta.depth == 1 then | 101 | if meta.depth == 1 then |
135 | return meta.pages.all:map(function(p) return d1_page_to_list_item(meta, p) end) | 102 | return meta.pages.all |
136 | end | 103 | end |
137 | 104 | ||
138 | if meta.depth == 2 then | 105 | if meta.depth == 2 then |
139 | return meta.pages.all | 106 | return meta.pages.all |
140 | :map(function(cat) | 107 | :map(function(cat) |
141 | local allItems = cat.pages.all:map(function(p) return d2_page_to_list_item(meta, cat, p, false) end) | 108 | local allItems = cat.pages.all:map(function(p) return d2_page_to_list_item(p, false) end) |
142 | 109 | ||
143 | return cat_to_list_cat(cat, allItems) | 110 | return cat_to_list_cat(cat, allItems) |
144 | end) | 111 | end) |
@@ -150,9 +117,9 @@ function generate_list(meta) | |||
150 | :map(function(cat) | 117 | :map(function(cat) |
151 | local allItems = cat.pages.all:flatMap(function(c) | 118 | local allItems = cat.pages.all:flatMap(function(c) |
152 | if cat.list_flatten and c.depth ~= 0 then | 119 | if cat.list_flatten and c.depth ~= 0 then |
153 | return c.pages.all:map(function(p) return d2_page_to_list_item(cat, c, p, true) end) | 120 | return c.pages.all:map(function(p) return d2_page_to_list_item(p, true) end) |
154 | else | 121 | else |
155 | return pandoc.List({ d1_page_to_list_item(cat, c) }) | 122 | return pandoc.List({ d1_page_to_list_item(c) }) |
156 | end | 123 | end |
157 | end) | 124 | end) |
158 | 125 | ||
@@ -166,6 +133,38 @@ function generate_list(meta) | |||
166 | end | 133 | end |
167 | end | 134 | end |
168 | 135 | ||
136 | function deref_page(pages) | ||
137 | return function(ref) | ||
138 | return pages[utils.stringify(ref)] | ||
139 | end | ||
140 | end | ||
141 | |||
142 | function process_pages(meta) | ||
143 | meta.pages.all = meta.pages.all:filterMap(deref_page(meta.pages.by_id)) | ||
144 | meta.pages.date_desc = meta.pages.date_desc:filterMap(deref_page(meta.pages.by_id)) | ||
145 | -- meta.pages.random = meta.pages.random:filterMap(deref_page(meta.pages.by_id)) | ||
146 | end | ||
147 | |||
148 | function resolve_urls(global, build, meta) | ||
149 | meta.url = resolve_url(global.site.url, build.file_out, meta.url) | ||
150 | |||
151 | if meta.feed then | ||
152 | if meta.file_out:match(".html$") then | ||
153 | meta.feed = { | ||
154 | url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")), | ||
155 | } | ||
156 | else | ||
157 | meta.page = { | ||
158 | url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")), | ||
159 | } | ||
160 | end | ||
161 | end | ||
162 | |||
163 | if meta.thumbnail then | ||
164 | meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) | ||
165 | end | ||
166 | end | ||
167 | |||
169 | function process_base(meta) | 168 | function process_base(meta) |
170 | meta.depth = tonumber(utils.stringify(meta.depth)) | 169 | meta.depth = tonumber(utils.stringify(meta.depth)) |
171 | meta.file_out = utils.stringify(meta.file_out) | 170 | meta.file_out = utils.stringify(meta.file_out) |
@@ -177,13 +176,25 @@ function process_base(meta) | |||
177 | meta.thumbnail = meta.thumbnail and utils.stringify(meta.thumbnail) | 176 | meta.thumbnail = meta.thumbnail and utils.stringify(meta.thumbnail) |
178 | end | 177 | end |
179 | 178 | ||
180 | function process(global, build, meta) | 179 | function process(global, build, meta, dir) |
181 | process_base(meta) | 180 | process_base(meta) |
182 | resolve_urls(global, build, meta) | 181 | resolve_urls(global, build, meta) |
183 | 182 | ||
184 | for _, p in pairs(meta.pages.by_id) do | 183 | if dir >= 0 then |
185 | process(global, build, p) | 184 | for _, p in pairs(meta.pages.by_id) do |
185 | p.parent = meta | ||
186 | process(global, build, p, 1) | ||
187 | p.parent = nil | ||
188 | end | ||
186 | end | 189 | end |
190 | |||
191 | process_pages(meta) | ||
192 | |||
193 | meta.list = generate_list(meta) | ||
194 | |||
195 | -- if dir <= 0 and meta.parent then | ||
196 | -- process(global, build, meta.parent, -1) | ||
197 | -- end | ||
187 | end | 198 | end |
188 | 199 | ||
189 | function Meta(meta) | 200 | function Meta(meta) |
@@ -206,8 +217,6 @@ function Meta(meta) | |||
206 | 217 | ||
207 | meta = meta.tree | 218 | meta = meta.tree |
208 | 219 | ||
209 | process(global, build, meta) | ||
210 | |||
211 | local parts = utils.stringify(build.namespace):split('/'):skip(1) | 220 | local parts = utils.stringify(build.namespace):split('/'):skip(1) |
212 | for i = 1, #parts do | 221 | for i = 1, #parts do |
213 | local part = parts[i] | 222 | local part = parts[i] |
@@ -217,9 +226,7 @@ function Meta(meta) | |||
217 | meta = p | 226 | meta = p |
218 | end | 227 | end |
219 | 228 | ||
220 | process_pages(global, build, meta) | 229 | process(global, build, meta, 0) |
221 | |||
222 | meta.list = generate_list(meta) | ||
223 | 230 | ||
224 | if global.menus and global.menus.main then | 231 | if global.menus and global.menus.main then |
225 | global.menus.main = prep_menu(meta.namespace.full, global.menus.main) | 232 | global.menus.main = prep_menu(meta.namespace.full, global.menus.main) |