let me put the âbreadcrumbâ content on the top part of the rendered page.
In Silverbullet V2 I seemed to understand that the same function was possible with the following code, but the widgets.breadcrumb() is not used.
Where am I going wrong?
widgets = widgets or {}
function widgets.breadcrumb()
local path = editor.getCurrentPage()
-- Funzione per suddividere la stringa in parti basate su "/"
local function split(str, sep)
local result = {}
for part in string.gmatch(str, "[^" .. sep .. "]+") do
table.insert(result, part)
end
return result
end
-- Divide il percorso in segmenti
local parts = split(path, "/")
-- Costruisce i breadcrumb escludendo l'ultimo elemento
local breadcrumbs = {}
local currentPath = ""
for i = 1, #parts - 1 do
if i == 1 then
currentPath = parts[i]
else
currentPath = currentPath .. "/" .. parts[i]
end
table.insert(breadcrumbs, "[[" .. currentPath .. "]]")
end
-- Restituisce i breadcrumb formattati
return table.concat(breadcrumbs, " > ")
end
event.listen {
name = "hooks:renderTopWidgets",
run = function(e)
return widgets.breadcrumb()
end
}
An extremely dirty workaround to that would be something like this:
event.listen {
name = "hooks:renderTopWidgets",
run = function(e)
return widget.new {markdown = "\n\n"..widgets.breadcrumb().."\n\n"}
end
}
But I do think that that is a bug.
About the conditional application, I think that it should be as easy as:
event.listen {
name = "hooks:renderTopWidgets",
run = function(e)
if not editor.getCurrentPage().startsWith("places/") then
return
end
return widget.new {markdown = "\n\n"..widgets.breadcrumb().."\n\n"}
end
}
Note: I am using editor.getCurrentPage() because _CTX.currentPage as specified in Space Lua for some reason has not been working for me