If each project has its own page with a category, moving dozens of pages into matching folders by hand is slow. This adds a command that moves every project page into a folder named after its category. It uses SilverBullet's own rename, so links to the pages keep working.
Each project page needs a tag and a category in its frontmatter, and must sit in one projects folder:
---
tags: project
category: Travel
---
CONFIG page, or any page you keep code on.space-lua code block (three backticks followed by space-lua) and paste this code inside it.System: Reload.-- Settings: the tag your project pages carry, and the folder they live in
FILE_BY_CATEGORY_TAG = "project"
FILE_BY_CATEGORY_FOLDER = "Projects/"
command.define {
name = "Projects: File by Category",
run = function()
local folder = FILE_BY_CATEGORY_FOLDER
local pages = query[
from p = index.pages(FILE_BY_CATEGORY_TAG)
where p.tag == "page" and p.category
and string.sub(p.name, 1, string.len(folder)) == folder
](<
from p = index.pages(FILE_BY_CATEGORY_TAG)
where p.tag == "page" and p.category
and string.sub(p.name, 1, string.len(folder)) == folder
>)
local moved = 0
for _, p in ipairs(pages) do
local leaf = string.match(p.name, "([^/]+)$")
local target = folder .. tostring(p.category) .. "/" .. leaf
if p.name ~= target then
system.invokeFunction("index.renamePageCommand", {oldPage = p.name, page = target})
moved = moved + 1
end
end
editor.flashNotification("Moved " .. moved .. " project pages")
end
}
Projects: File by Category.category: Travel moves to Projects/Travel/ plus its page name.