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 --- Makefile | 4 +++- metadata/metadata.yaml | 30 +++++++++++++++--------------- scripts/page.lua | 31 ++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index aaf589d..9e389b3 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,9 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ --metadata-file "$<" \ --metadata build.mode="$(MODE)" \ --template scripts/metadata.json \ - -o "$@" "$<" + -o "$@.meta" "$<" + jq '{ tree: . }' "$@.meta" > "$@" + rm "$@.meta" .cache/assets.json: $(ASSET_FILES) | .cache $(info [ASET] $@) diff --git a/metadata/metadata.yaml b/metadata/metadata.yaml index 4320b36..3baf3b9 100644 --- a/metadata/metadata.yaml +++ b/metadata/metadata.yaml @@ -7,22 +7,22 @@ author: menus: main: - - id: art - label: Art - url: /art/ + - label: Art + match: [^/art/, ^/art$] + url: /art/ - - id: projects - label: Projects - url: /projects/ + - label: Projects + match: [^/projects/, ^/projects$] + url: /projects/ - - id: notebook - label: Notebook - url: /notebook/ + - label: Notebook + match: [^/notebook/, ^/notebook$] + url: /notebook/ - - id: profiles - label: Profiles - url: /profiles/ + - label: Profiles + match: [^/profiles/, ^/profiles$] + url: /profiles/ - - id: services - label: Services - url: /services/ + - label: Services + match: [^/services/, ^/services$] + url: /services/ 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-70-g09d2