plugin/breadcrumb.lua

Sun, 06 Aug 2023 21:12:43 +0300

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 06 Aug 2023 21:12:43 +0300
changeset 43
20606bf1a6a0
parent 42
260f867d46c0
permissions
-rwxr-xr-x

Load markdown-it-container


--@module plugin.breadcrumb

local plugin_breadcrumb={}

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
                      "???"

        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