summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/metadata.lua4
-rw-r--r--scripts/page.lua33
2 files changed, 25 insertions, 12 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)