I’ve been banging my head against a wall for a few days trying to migrate my index page to Silverbullet v2. Using Lua for this setup seems extremely convoluted or outright impossible currently, but it might just be me so I’m reaching out for help.
In case you still have a v1 setup, here are the relevant pages:
In detail:
silverbullet_index.md is the index page. It displays a list of clickable tags, each with a count of tagged pages, a list of tasks grouped by page, and a list of the last 15 pages created in your space. Also includes a link to “All pages” that shows all your pages in the same format.
tagcount.md contains the tagCount function that is used for counting tags in the other pages in this setup.
All pages.md lists all the pages in your space using the same format as the index page.
Any help on how I should approach the migration would be greatly appreciated. I’m still on v1 mainly because I rely very heavily on this setup and also attribute extractors, but that’s a separate issue.
Phew. After a few more hours of head banging, I’m pretty close to where I want to be. Here’s my current v2 index page:
# TAGS
${template.each(query[[from index.tag "tag" select {name = _.name} where not string.find(name, "meta")]], home.renderTag)}
# TASKS
${template.each(query[[from index.tag "task" select {currentPage = _.page} where not _.done]], template.new[==[
**[[${currentPage}]]** ${template.each(query[[from index.tag "tag" where _.page == currentPage]], home.renderTag)}
${template.each(query[[from index.tag "task" where _.page == currentPage and not _.done]], home.renderTask)}
]==])}
# LATEST
[[All pages|Show all]]
${template.each(query[[from index.tag "page" where not string.find(_.name,"Library") order by created desc limit 15]], home.renderPage)}
Here’s the space-lua for the home.* functions, which I put on a separate page:
home = home or {}
home.renderTag = template.new[==[_[[tag:${name}|#${name}]]_ ]==]
home.renderTask = template.new[==[- ${text}
]==]
home.renderPage = template.new[==[### [[${name}]]
${created}
]==]
And finally the ‘All pages’ page to list everything using the same format:
# All pages
${template.each(query[[from index.tag "page" where not string.find(_.name,"Library") order by created desc]], home.renderPage)}
I would love to refactor this to make it more readable, so if anybody has any input or just wants to give it a shot I would appreciate it. Still missing from my v1 setup is the following:
Remove the table of contents from the page
Add a tag count to each tag in the Tags section
Show a list of tags for each page in the Latest section
Less verbose creation date for each page in the Latest section
Exclude #meta pages from the list. Right now, as a simple workaround, I’m excluding pages that contain the string “Library” in the name.