Sun, 06 Aug 2023 14:32:25 +0300
Preliminary breadcrumb support
handlers/render.lua | file | annotate | diff | comparison | revisions | |
lgen.lua | file | annotate | diff | comparison | revisions | |
plugin/breadcrumb.lua | file | annotate | diff | comparison | revisions |
--- a/handlers/render.lua Wed Dec 15 10:37:47 2021 +0200 +++ b/handlers/render.lua Sun Aug 06 14:32:25 2023 +0300 @@ -85,6 +85,7 @@ function handlers_render.env_for(file, env, path_prefix) local newenv=table.copy(env) + newenv.source_file=file newenv.base_url=path.to_root(file) newenv.path_prefix=(path_prefix or "") newenv.page=env.pages[file]
--- a/lgen.lua Wed Dec 15 10:37:47 2021 +0200 +++ b/lgen.lua Sun Aug 06 14:32:25 2023 +0300 @@ -32,7 +32,7 @@ print('Scan...') -local hierarchy = scan.scan(src) +hierarchy = scan.scan(src) local env={
--- a/plugin/breadcrumb.lua Wed Dec 15 10:37:47 2021 +0200 +++ b/plugin/breadcrumb.lua Sun Aug 06 14:32:25 2023 +0300 @@ -3,10 +3,42 @@ local plugin_breadcrumb={} -local path=require("mypath") +function plugin_breadcrumb.trail(env, separator, final_separator) + local f = env.source_file; + local res = "" + local next_separator = final_separator + local path = "../" + + function do_page(f) + local title = env.pages[f].meta.h1_title or + env.pages[f].meta.title or + "???" -function plugin_breadcrumb.trail(env) - return "(TODO)" + if env.pages[f] then + res = next_separator .. res + next_separator = separator + res = string.format("<a href=\"%s\">%s</a>", path, title) .. res + path = "../" .. path + end + end + + while true do + print(f) + local p, ext = f:match("(.*/)[^/]+/[^/.]+%.([^/]+)") + if p then + f = p .. "index." .. ext + do_page(f) + else + break + end + end + + local ext = f:match("[^/]+/[^/.]+%.([^/]+)") + if ext then + do_page("index." .. ext) + end + + return res end return plugin_breadcrumb