The two biggest things I use it for are programmatically generating “lists of lists” (lists of pages, more accurately) and as a semi-hacky way to get text colors. Semi-related, the “Treeview” plugin gives you a folder hierarchy panel off to the left (by default) which is really, really nice.
I should probably clarify that I didn’t write these, I stole them from the Silverbullet community forums… also I should reiterate that I suck at Lua so take my explanations with a grain of “this person may not know what they’re talking about” ; )
**Lists of Lists : **
I have a bad memory so I create a LOT of lists. I even have a base page named “Lists” that I then nest different types of lists under (TODOs for home, for work, for school, for projects, for selfhosting, etc). This first snippet relies on using frontmatter on the respective pages along with the tags property.
${query[[
from index.tag "todolist"
order by lastModified desc
select {
List="[[" .. _.name .. "]]",
Modified=_.lastModified
}
]]}
This retrieves all pages from the space index with a tag of todolist (from the frontmatter), orders them by lastModified, descending, and renders a table that contains the name and lastModified date. This is excellent for providing a list of pages (based on tag, todolist in this case) related to a topic and ordering them by the last time they were changed. I use this in the base page for pretty much all of my “folders”. Screenshot :
Text Color Hack :
Since the Silverbullet markdown interpreter doesn’t (currently) support plain HTML, and the way we usually color specific areas of text within Markdown is <span style=“color: #fff”>white text</span>, they had to get inventive. Somebody came up with a way to provide Lua functions that will accept text as a parameter and then render it with the specified HTML color/style.
In my CONFIG page (that is applied to the entire space) I included a space-lua code block like :
function Red(text)
return widget.html(dom.span {
style="color:#e60000; font-weight: bold;",
text
})
end
// Also about 5 more for different colors I use, snipped for simplicity.
Then, anywhere in my Silverbullet space I can use a Lua code snippet like The following word is ${Red(“red”)} and it will invoke the space-lua function named Red() on the text red, apply the styling, and render it with CSS color #e60000. Hacky? Yeah… but it works for now. Screenshot :