From 0e6d2cf355fc675735e729126efc26b583acdb5f Mon Sep 17 00:00:00 2001 From: Volpeon Date: Thu, 4 Aug 2022 11:16:31 +0200 Subject: Made parent page accessible; more flexible main menu by using patterns insteda of IDs --- scripts/page.lua | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'scripts') 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) return { abs = abs, rel = rel, full = full } end -function prep_menu(active_id, main_menu) - active_id = utils.stringify(active_id) +function prep_menu(namespace, main_menu) + namespace = utils.stringify(namespace) local active_item = nil local items = pandoc.List() for i = 1, #main_menu do local item = main_menu[i] - local active = utils.stringify(item.id) == active_id - item.active = active - if active then active_item = item end + for j = 1, #item.match do + if active_item then break end + item.active = not not namespace:match(utils.stringify(item.match[j])) + if item.active then active_item = item end + end if not item.hidden or item.active then items:insert(item) end end @@ -35,7 +37,7 @@ end function process_pages(global, build, meta) for _, p in pairs(meta.pages.by_id) do - process(global, build, p) + process_pages(global, build, p) end meta.pages = { @@ -178,7 +180,10 @@ end function process(global, build, meta) process_base(meta) resolve_urls(global, build, meta) - process_pages(global, build, meta) + + for _, p in pairs(meta.pages.by_id) do + process(global, build, p) + end end function Meta(meta) @@ -199,17 +204,25 @@ function Meta(meta) menus = meta.menus } + meta = meta.tree + process(global, build, meta) local parts = utils.stringify(build.namespace):split('/'):skip(1) for i = 1, #parts do - meta = meta.pages.by_id[parts[i]] + local part = parts[i] + local p = meta.pages.by_id[part] + meta.pages.by_id[part] = nil + p.parent = meta + meta = p end + process_pages(global, build, meta) + meta.list = generate_list(meta) if global.menus and global.menus.main then - global.menus.main = prep_menu(meta.namespace.root.id, global.menus.main) + global.menus.main = prep_menu(meta.namespace.full, global.menus.main) end for key, value in pairs(global) do -- cgit v1.2.3-54-g00ecf