# HG changeset patch # User Tuomo Valkonen # Date 1691321545 -10800 # Node ID 260f867d46c0ccbaf612b64590aca25836a9ec7b # Parent 8040d3a298e4895dac6fc771beac648c75f11d22 Preliminary breadcrumb support diff -r 8040d3a298e4 -r 260f867d46c0 handlers/render.lua --- 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] diff -r 8040d3a298e4 -r 260f867d46c0 lgen.lua --- 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={ diff -r 8040d3a298e4 -r 260f867d46c0 plugin/breadcrumb.lua --- 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("%s", 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