summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-08-04 11:16:31 +0200
committerVolpeon <git@volpeon.ink>2022-08-04 11:16:31 +0200
commit0e6d2cf355fc675735e729126efc26b583acdb5f (patch)
treed566cc3d4196bd377336ab4ab1ae1f33673c58f5 /scripts
parentOverhauled metadata handling (diff)
downloadvolpeon.ink-0e6d2cf355fc675735e729126efc26b583acdb5f.tar.gz
volpeon.ink-0e6d2cf355fc675735e729126efc26b583acdb5f.tar.bz2
volpeon.ink-0e6d2cf355fc675735e729126efc26b583acdb5f.zip
Made parent page accessible; more flexible main menu by using patterns insteda of IDs
Diffstat (limited to 'scripts')
-rw-r--r--scripts/page.lua31
1 files changed, 22 insertions, 9 deletions
diff --git a/scripts/page.lua b/scripts/page.lua
index e846dd5..3df55ec 100644
--- a/scripts/page.lua
+++ b/scripts/page.lua
@@ -16,17 +16,19 @@ function resolve_url(site_url, ref_file, target_file)
16 return { abs = abs, rel = rel, full = full } 16 return { abs = abs, rel = rel, full = full }
17end 17end
18 18
19function prep_menu(active_id, main_menu) 19function prep_menu(namespace, main_menu)
20 active_id = utils.stringify(active_id) 20 namespace = utils.stringify(namespace)
21 21
22 local active_item = nil 22 local active_item = nil
23 local items = pandoc.List() 23 local items = pandoc.List()
24 24
25 for i = 1, #main_menu do 25 for i = 1, #main_menu do
26 local item = main_menu[i] 26 local item = main_menu[i]
27 local active = utils.stringify(item.id) == active_id 27 for j = 1, #item.match do
28 item.active = active 28 if active_item then break end
29 if active then active_item = item end 29 item.active = not not namespace:match(utils.stringify(item.match[j]))
30 if item.active then active_item = item end
31 end
30 if not item.hidden or item.active then items:insert(item) end 32 if not item.hidden or item.active then items:insert(item) end
31 end 33 end
32 34
@@ -35,7 +37,7 @@ end
35 37
36function process_pages(global, build, meta) 38function process_pages(global, build, meta)
37 for _, p in pairs(meta.pages.by_id) do 39 for _, p in pairs(meta.pages.by_id) do
38 process(global, build, p) 40 process_pages(global, build, p)
39 end 41 end
40 42
41 meta.pages = { 43 meta.pages = {
@@ -178,7 +180,10 @@ end
178function process(global, build, meta) 180function process(global, build, meta)
179 process_base(meta) 181 process_base(meta)
180 resolve_urls(global, build, meta) 182 resolve_urls(global, build, meta)
181 process_pages(global, build, meta) 183
184 for _, p in pairs(meta.pages.by_id) do
185 process(global, build, p)
186 end
182end 187end
183 188
184function Meta(meta) 189function Meta(meta)
@@ -199,17 +204,25 @@ function Meta(meta)
199 menus = meta.menus 204 menus = meta.menus
200 } 205 }
201 206
207 meta = meta.tree
208
202 process(global, build, meta) 209 process(global, build, meta)
203 210
204 local parts = utils.stringify(build.namespace):split('/'):skip(1) 211 local parts = utils.stringify(build.namespace):split('/'):skip(1)
205 for i = 1, #parts do 212 for i = 1, #parts do
206 meta = meta.pages.by_id[parts[i]] 213 local part = parts[i]
214 local p = meta.pages.by_id[part]
215 meta.pages.by_id[part] = nil
216 p.parent = meta
217 meta = p
207 end 218 end
208 219
220 process_pages(global, build, meta)
221
209 meta.list = generate_list(meta) 222 meta.list = generate_list(meta)
210 223
211 if global.menus and global.menus.main then 224 if global.menus and global.menus.main then
212 global.menus.main = prep_menu(meta.namespace.root.id, global.menus.main) 225 global.menus.main = prep_menu(meta.namespace.full, global.menus.main)
213 end 226 end
214 227
215 for key, value in pairs(global) do 228 for key, value in pairs(global) do