summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/metadata.lua20
-rw-r--r--scripts/page.lua41
2 files changed, 42 insertions, 19 deletions
diff --git a/scripts/metadata.lua b/scripts/metadata.lua
index 49a9c55..9c8a964 100644
--- a/scripts/metadata.lua
+++ b/scripts/metadata.lua
@@ -130,6 +130,7 @@ end
130 130
131function process_base(build, meta) 131function process_base(build, meta)
132 meta.namespace = prep_namespace(meta.namespace) 132 meta.namespace = prep_namespace(meta.namespace)
133 meta.id = meta.namespace.full:gsub("^.*/(.-)$", "%1")
133 meta.file_out = utils.stringify(meta.file_out) 134 meta.file_out = utils.stringify(meta.file_out)
134 meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") 135 meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev")
135 meta.redirect = meta.url and true 136 meta.redirect = meta.url and true
@@ -164,6 +165,24 @@ function process(global, build, meta)
164 resolve_dates(meta) 165 resolve_dates(meta)
165end 166end
166 167
168function find_pos(meta)
169 for _, p in pairs(meta.pages.by_id) do
170 p.parent = meta
171 find_pos(p)
172 p.parent = nil
173 end
174
175 if not meta.parent then return end
176
177 local pages = meta.parent.list_order == "date_desc" and meta.parent.pages.date_desc or meta.parent.pages.all
178 local _, index = pages:find(meta.id)
179
180 if index == nil then return end
181
182 meta.prev = index >= 2 and pages[index - 1] or nil
183 meta.next = index <= #pages - 1 and pages[index + 1] or nil
184end
185
167function Meta(meta) 186function Meta(meta)
168 local build = {} 187 local build = {}
169 188
@@ -180,6 +199,7 @@ function Meta(meta)
180 199
181 find_depth(meta) 200 find_depth(meta)
182 process(meta, build, meta) 201 process(meta, build, meta)
202 find_pos(meta)
183 203
184 return meta 204 return meta
185end 205end
diff --git a/scripts/page.lua b/scripts/page.lua
index dcbb36f..7378bfc 100644
--- a/scripts/page.lua
+++ b/scripts/page.lua
@@ -130,32 +130,35 @@ function generate_list(meta)
130 end 130 end
131end 131end
132 132
133function deref_page(pages)
134 return function(ref)
135 return pages[utils.stringify(ref)]
136 end
137end
138
133function generate_related(meta) 139function generate_related(meta)
134 if not meta.parent then return nil end 140 if not meta.parent then return nil end
135 141
136 meta = meta.parent 142 local deref = deref_page(meta.parent.pages.by_id)
137 143
138 local items = meta.pages.random:take(2):map(function (p) return d1_page_to_list_item(p) end) 144 meta.prev = meta.prev and d1_page_to_list_item(deref(meta.prev))
145 meta.next = meta.next and d1_page_to_list_item(deref(meta.next))
139 146
140 if #items == 0 then return nil end 147 if not meta.prev and not meta.next then return nil end
141 148
142 return { 149 return {
143 url = meta.url, 150 url = meta.parent.url,
144 layout = meta.list_layout, 151 layout = meta.parent.list_layout,
145 items = items 152 prev = meta.prev,
153 next = meta.next
146 } 154 }
147end 155end
148 156
149function deref_page(pages)
150 return function(ref)
151 return pages[utils.stringify(ref)]
152 end
153end
154
155function process_pages(meta) 157function process_pages(meta)
156 meta.pages.all = meta.pages.all:filterMap(deref_page(meta.pages.by_id)) 158 local deref = deref_page(meta.pages.by_id)
157 meta.pages.date_desc = meta.pages.date_desc:filterMap(deref_page(meta.pages.by_id)) 159
158 meta.pages.random = meta.pages.all :clone():shuffle() 160 meta.pages.all = meta.pages.all:filterMap(deref)
161 meta.pages.date_desc = meta.pages.date_desc:filterMap(deref)
159end 162end
160 163
161function resolve_urls(global, build, meta) 164function resolve_urls(global, build, meta)
@@ -179,6 +182,7 @@ function resolve_urls(global, build, meta)
179end 182end
180 183
181function process_base(meta) 184function process_base(meta)
185 meta.id = utils.stringify(meta.id)
182 meta.depth = tonumber(utils.stringify(meta.depth)) 186 meta.depth = tonumber(utils.stringify(meta.depth))
183 meta.file_out = utils.stringify(meta.file_out) 187 meta.file_out = utils.stringify(meta.file_out)
184 meta.url = utils.stringify(meta.url) 188 meta.url = utils.stringify(meta.url)
@@ -187,6 +191,8 @@ function process_base(meta)
187 meta.list_order = meta.list_order and utils.stringify(meta.list_order) 191 meta.list_order = meta.list_order and utils.stringify(meta.list_order)
188 meta.position = meta.position and tonumber(utils.stringify(meta.position)) 192 meta.position = meta.position and tonumber(utils.stringify(meta.position))
189 meta.thumbnail = meta.thumbnail and utils.stringify(meta.thumbnail) 193 meta.thumbnail = meta.thumbnail and utils.stringify(meta.thumbnail)
194 meta.prev = meta.prev and utils.stringify(meta.prev)
195 meta.next = meta.next and utils.stringify(meta.next)
190end 196end
191 197
192function process(global, build, meta, dir) 198function process(global, build, meta, dir)
@@ -207,7 +213,6 @@ function process(global, build, meta, dir)
207end 213end
208 214
209function prune_pages(meta, up, down) 215function prune_pages(meta, up, down)
210 meta.pages.random = pandoc.List()
211 meta.pages.by_id = {} 216 meta.pages.by_id = {}
212 217
213 if down == 0 then 218 if down == 0 then
@@ -231,8 +236,6 @@ function prune(meta, up, down)
231end 236end
232 237
233function Meta(meta) 238function Meta(meta)
234 math.randomseed(os.time())
235
236 local build = {} 239 local build = {}
237 240
238 for key, value in pairs(meta) do 241 for key, value in pairs(meta) do
@@ -254,7 +257,7 @@ function Meta(meta)
254 257
255 meta = meta.tree 258 meta = meta.tree
256 259
257 local parts = utils.stringify(build.namespace):split('/'):skip(1) 260 local parts = build.namespace:split('/'):skip(1)
258 for i = 1, #parts do 261 for i = 1, #parts do
259 local part = parts[i] 262 local part = parts[i]
260 local p = meta.pages.by_id[part] 263 local p = meta.pages.by_id[part]