Sun, 06 Aug 2023 21:12:43 +0300
Load markdown-it-container
3 | 1 | |
9
751216807683
Further lua5.3 compatibility fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
3
diff
changeset
|
2 | --@module plugin.breadcrumb |
3 | 3 | |
9
751216807683
Further lua5.3 compatibility fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
3
diff
changeset
|
4 | local plugin_breadcrumb={} |
3 | 5 | |
42
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
6 | function plugin_breadcrumb.trail(env, separator, final_separator) |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
7 | local f = env.source_file; |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
8 | local res = "" |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
9 | local next_separator = final_separator |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
10 | local path = "../" |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
11 | |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
12 | function do_page(f) |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
13 | local title = env.pages[f].meta.h1_title or |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
14 | env.pages[f].meta.title or |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
15 | "???" |
9
751216807683
Further lua5.3 compatibility fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
3
diff
changeset
|
16 | |
42
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
17 | if env.pages[f] then |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
18 | res = next_separator .. res |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
19 | next_separator = separator |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
20 | res = string.format("<a href=\"%s\">%s</a>", path, title) .. res |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
21 | path = "../" .. path |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
22 | end |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
23 | end |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
24 | |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
25 | while true do |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
26 | print(f) |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
27 | local p, ext = f:match("(.*/)[^/]+/[^/.]+%.([^/]+)") |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
28 | if p then |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
29 | f = p .. "index." .. ext |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
30 | do_page(f) |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
31 | else |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
32 | break |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
33 | end |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
34 | end |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
35 | |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
36 | local ext = f:match("[^/]+/[^/.]+%.([^/]+)") |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
37 | if ext then |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
38 | do_page("index." .. ext) |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
39 | end |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
40 | |
260f867d46c0
Preliminary breadcrumb support
Tuomo Valkonen <tuomov@iki.fi>
parents:
26
diff
changeset
|
41 | return res |
3 | 42 | end |
9
751216807683
Further lua5.3 compatibility fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
3
diff
changeset
|
43 | |
751216807683
Further lua5.3 compatibility fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
3
diff
changeset
|
44 | return plugin_breadcrumb |