summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-08-05 18:06:20 +0200
committerVolpeon <git@volpeon.ink>2022-08-05 18:06:20 +0200
commit6de1ad4cdc8b1fb10cf0a5c61d5ed03893f131c1 (patch)
tree5df16cd2a5d4938016346971a53968c398206624
parentStricter pruning, don't pre-calculate description field (diff)
downloadvolpeon.ink-6de1ad4cdc8b1fb10cf0a5c61d5ed03893f131c1.tar.gz
volpeon.ink-6de1ad4cdc8b1fb10cf0a5c61d5ed03893f131c1.tar.bz2
volpeon.ink-6de1ad4cdc8b1fb10cf0a5c61d5ed03893f131c1.zip
Show related content
-rw-r--r--scripts/metadata.lua4
-rw-r--r--scripts/page.lua33
-rw-r--r--templates/layouts/exhibit.html2
-rw-r--r--templates/layouts/page.html4
-rw-r--r--templates/partials/related.html35
5 files changed, 64 insertions, 14 deletions
diff --git a/scripts/metadata.lua b/scripts/metadata.lua
index d0a4f45..49a9c55 100644
--- a/scripts/metadata.lua
+++ b/scripts/metadata.lua
@@ -84,12 +84,10 @@ function process_pages(meta)
84 84
85 pages_all:sort(sort.page_sort(meta.list_order, meta.pages)) 85 pages_all:sort(sort.page_sort(meta.list_order, meta.pages))
86 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()
88 87
89 meta.pages = { 88 meta.pages = {
90 all = pages_all, 89 all = pages_all,
91 date_desc = pages_date_desc, 90 date_desc = pages_date_desc,
92 random = pages_random,
93 by_id = meta.pages 91 by_id = meta.pages
94 } 92 }
95end 93end
@@ -167,8 +165,6 @@ function process(global, build, meta)
167end 165end
168 166
169function Meta(meta) 167function Meta(meta)
170 math.randomseed(os.time())
171
172 local build = {} 168 local build = {}
173 169
174 for key, value in pairs(meta) do 170 for key, value in pairs(meta) do
diff --git a/scripts/page.lua b/scripts/page.lua
index f3802a2..dcbb36f 100644
--- a/scripts/page.lua
+++ b/scripts/page.lua
@@ -96,7 +96,7 @@ function generate_list(meta)
96 if meta.depth < 1 then return pandoc.List() end 96 if meta.depth < 1 then return pandoc.List() end
97 97
98 if meta.depth == 1 then 98 if meta.depth == 1 then
99 return meta.pages.all 99 return meta.pages.all:map(function (p) return d1_page_to_list_item(p) end)
100 end 100 end
101 101
102 if meta.depth == 2 then 102 if meta.depth == 2 then
@@ -130,6 +130,22 @@ function generate_list(meta)
130 end 130 end
131end 131end
132 132
133function generate_related(meta)
134 if not meta.parent then return nil end
135
136 meta = meta.parent
137
138 local items = meta.pages.random:take(2):map(function (p) return d1_page_to_list_item(p) end)
139
140 if #items == 0 then return nil end
141
142 return {
143 url = meta.url,
144 layout = meta.list_layout,
145 items = items
146 }
147end
148
133function deref_page(pages) 149function deref_page(pages)
134 return function(ref) 150 return function(ref)
135 return pages[utils.stringify(ref)] 151 return pages[utils.stringify(ref)]
@@ -139,7 +155,7 @@ end
139function process_pages(meta) 155function process_pages(meta)
140 meta.pages.all = meta.pages.all:filterMap(deref_page(meta.pages.by_id)) 156 meta.pages.all = meta.pages.all:filterMap(deref_page(meta.pages.by_id))
141 meta.pages.date_desc = meta.pages.date_desc:filterMap(deref_page(meta.pages.by_id)) 157 meta.pages.date_desc = meta.pages.date_desc:filterMap(deref_page(meta.pages.by_id))
142 meta.pages.random = meta.pages.random:filterMap(deref_page(meta.pages.by_id)) 158 meta.pages.random = meta.pages.all :clone():shuffle()
143end 159end
144 160
145function resolve_urls(global, build, meta) 161function resolve_urls(global, build, meta)
@@ -177,12 +193,10 @@ function process(global, build, meta, dir)
177 process_base(meta) 193 process_base(meta)
178 resolve_urls(global, build, meta) 194 resolve_urls(global, build, meta)
179 195
180 if dir >= 0 then 196 for _, p in pairs(meta.pages.by_id) do
181 for _, p in pairs(meta.pages.by_id) do 197 p.parent = meta
182 p.parent = meta 198 process(global, build, p, 1)
183 process(global, build, p, 1) 199 p.parent = nil
184 p.parent = nil
185 end
186 end 200 end
187 201
188 process_pages(meta) 202 process_pages(meta)
@@ -217,6 +231,8 @@ function prune(meta, up, down)
217end 231end
218 232
219function Meta(meta) 233function Meta(meta)
234 math.randomseed(os.time())
235
220 local build = {} 236 local build = {}
221 237
222 for key, value in pairs(meta) do 238 for key, value in pairs(meta) do
@@ -250,6 +266,7 @@ function Meta(meta)
250 process(global, build, meta, 0) 266 process(global, build, meta, 0)
251 267
252 meta.list = generate_list(meta) 268 meta.list = generate_list(meta)
269 meta.related = generate_related(meta)
253 270
254 if global.menus and global.menus.main then 271 if global.menus and global.menus.main then
255 global.menus.main = prep_menu(meta.namespace.full, global.menus.main) 272 global.menus.main = prep_menu(meta.namespace.full, global.menus.main)
diff --git a/templates/layouts/exhibit.html b/templates/layouts/exhibit.html
index fcc92a4..7a50635 100644
--- a/templates/layouts/exhibit.html
+++ b/templates/layouts/exhibit.html
@@ -53,6 +53,8 @@
53$body$ 53$body$
54 </div> 54 </div>
55 </div> 55 </div>
56
57 $partials/related()$
56 </div> 58 </div>
57</main> 59</main>
58 60
diff --git a/templates/layouts/page.html b/templates/layouts/page.html
index f26c4bc..b1f7835 100644
--- a/templates/layouts/page.html
+++ b/templates/layouts/page.html
@@ -30,8 +30,6 @@ $body$
30 30
31 $if(references)$ 31 $if(references)$
32 <footer class="s-colored-links s-lists"> 32 <footer class="s-colored-links s-lists">
33 <hr />
34
35 <h1>References</h1> 33 <h1>References</h1>
36 <ul> 34 <ul>
37 $for(references)$ 35 $for(references)$
@@ -40,6 +38,8 @@ $body$
40 </ul> 38 </ul>
41 </footer> 39 </footer>
42 $endif$ 40 $endif$
41
42 $partials/related()$
43 </article> 43 </article>
44 44
45 <div class="o-backdrop js-lightbox u-d-none t-dark"> 45 <div class="o-backdrop js-lightbox u-d-none t-dark">
diff --git a/templates/partials/related.html b/templates/partials/related.html
new file mode 100644
index 0000000..b0d3f61
--- /dev/null
+++ b/templates/partials/related.html
@@ -0,0 +1,35 @@
1$if(related)$
2 <footer>
3 <hr class="u-mt-700" />
4
5 <div class="l-card-list">
6 <header class="l-card-list__header">
7 <h2 class="s-invisible-links u-mt-0">
8 $if(related.url)$
9 <a href="$related.url.rel$">Related</a>
10 $else$
11 Related
12 $endif$
13 </h2>
14 </header>
15 <div class="l-card-list__cards l-card-list__cards--$related.layout.id$">
16 $if(related.layout.is_grid-2)$
17 $related.items:partials/grid_card()$
18 $elseif(related.layout.is_grid-3)$
19 $related.items:partials/grid_card()$
20 $elseif(related.layout.is_gallery-2)$
21 $related.items:partials/gallery_card()$
22 $elseif(related.layout.is_gallery-3)$
23 $related.items:partials/gallery_card()$
24 $else$
25 <div class="u-d-contents u-d-none@sm-lo">
26 $related.items:partials/list_card()$
27 </div>
28 <div class="u-d-contents u-d-none@sm-hi">
29 $related.items:partials/grid_card()$
30 </div>
31 $endif$
32 </div>
33 </div>
34 </footer>
35$endif$