plugin/breadcrumb.lua

changeset 42
260f867d46c0
parent 26
77cd7b8fb6a6
--- 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

mercurial