I was confused myself but without the second block (see below), my space doesn’t recognize the template command names nor do the templates show up in the list under “Page: From Template”
Here is my total CONFIG
file:
config.set {
plugs = {
"github:joekrill/silverbullet-treeview/treeview.plug.js"
},
actionButtons = {
{
icon = "home",
description = "Go to the index page",
run = function()
editor.invokeCommand("Navigate: Home")
end
},
{
icon = "activity",
description = "What's new",
run = function()
editor.navigate {
page = "CHANGELOG"
}
end
},
{
icon = "message-circle",
description = "Community",
run = function()
editor.openUrl "https://community.silverbullet.md"
end
},
{
icon = "book",
description = "Open page",
run = function()
editor.invokeCommand("Navigate: Page Picker")
end
},
{
icon = "terminal",
description = "Run command",
run = function()
editor.invokeCommand "Open Command Palette"
end,
}
},
smartQuotes = {
enabled = true,
},
queryCollate = {
enabled = true,
locale = "en",
options = {
caseFirst = "upper"
}
}
}
-- priority: 10
local function createPageFromTemplate(templatePage, pageName)
-- Won't override an existing page
if space.pageExists(pageName) then
editor.flashNotification("Page " .. pageName .. " already exists", "error")
return
end
local tpl, fm = template.fromPage(templatePage)
local initialText = ""
if fm.frontmatter then
initialText = "---\n"
.. string.trim(template.new(fm.frontmatter)())
.. "\n---\n"
end
-- Write an empty page to start
space.writePage(pageName, initialText)
editor.navigate({kind = "page", page = pageName})
-- Insert there, supporting |^| cursor placeholder
editor.insertAtPos(tpl(), #initialText, true)
end
-- Create commands for all page templates with a command key in frontmatter
for pt in query[[
from index.tag "meta/template/page"
where _.tag == "page" and _.command
order by _.priority desc
]] do
command.define {
name = pt.command,
key = pt.key,
mac = pt.mac,
run = function()
local pageName
if pt.suggestedName then
pageName = (template.new(pt.suggestedName))()
end
if pt.confirmName != false then
pageName = editor.prompt("Page name", pageName)
end
if not pageName then
return
end
if pt.openIfExists and space.pageExists(pageName) then
editor.navigate({kind = "page", page = pageName})
return
end
createPageFromTemplate(pt.name, pageName)
end
}
print("Registered", pt.command)
end
command.define {
name = "Page: From Template",
run = function()
local pageTemplates = query[[from index.tag "meta/template/page" where _.tag == "page"]]
local selected = editor.filterBox("Page template", pageTemplates, "Pick the template you would like to instantiate")
if not selected then
return
end
local pageName
if selected.suggestedName then
pageName = (template.new(selected.suggestedName))()
end
pageName = editor.prompt("Page name", pageName)
if not pageName then
return
end
createPageFromTemplate(selected.name, pageName)
end
}