diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | metadata/metadata.yaml | 30 | ||||
-rw-r--r-- | scripts/page.lua | 31 |
3 files changed, 40 insertions, 25 deletions
@@ -96,7 +96,9 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ | |||
96 | --metadata-file "$<" \ | 96 | --metadata-file "$<" \ |
97 | --metadata build.mode="$(MODE)" \ | 97 | --metadata build.mode="$(MODE)" \ |
98 | --template scripts/metadata.json \ | 98 | --template scripts/metadata.json \ |
99 | -o "$@" "$<" | 99 | -o "$@.meta" "$<" |
100 | jq '{ tree: . }' "$@.meta" > "$@" | ||
101 | rm "$@.meta" | ||
100 | 102 | ||
101 | .cache/assets.json: $(ASSET_FILES) | .cache | 103 | .cache/assets.json: $(ASSET_FILES) | .cache |
102 | $(info [ASET] $@) | 104 | $(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: | |||
7 | 7 | ||
8 | menus: | 8 | menus: |
9 | main: | 9 | main: |
10 | - id: art | 10 | - label: Art |
11 | label: Art | 11 | match: [^/art/, ^/art$] |
12 | url: /art/ | 12 | url: /art/ |
13 | 13 | ||
14 | - id: projects | 14 | - label: Projects |
15 | label: Projects | 15 | match: [^/projects/, ^/projects$] |
16 | url: /projects/ | 16 | url: /projects/ |
17 | 17 | ||
18 | - id: notebook | 18 | - label: Notebook |
19 | label: Notebook | 19 | match: [^/notebook/, ^/notebook$] |
20 | url: /notebook/ | 20 | url: /notebook/ |
21 | 21 | ||
22 | - id: profiles | 22 | - label: Profiles |
23 | label: Profiles | 23 | match: [^/profiles/, ^/profiles$] |
24 | url: /profiles/ | 24 | url: /profiles/ |
25 | 25 | ||
26 | - id: services | 26 | - label: Services |
27 | label: Services | 27 | match: [^/services/, ^/services$] |
28 | url: /services/ | 28 | 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) | |||
16 | return { abs = abs, rel = rel, full = full } | 16 | return { abs = abs, rel = rel, full = full } |
17 | end | 17 | end |
18 | 18 | ||
19 | function prep_menu(active_id, main_menu) | 19 | function 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 | ||
36 | function process_pages(global, build, meta) | 38 | function 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 | |||
178 | function process(global, build, meta) | 180 | function 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 | ||
182 | end | 187 | end |
183 | 188 | ||
184 | function Meta(meta) | 189 | function 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 |