Hi, can you give me a hint, how to finde orphaned attachments in a Silverbullet Space? I didn't find a clue in the documentation.
Other Tools provides features or Plugins to identify attachments, which are no longer linked from pages.
Here is my solution. Open tree view and select "view document". When you click on the orphan document you will see in the tree the document selected (feature of SB). There is an icon to delete the document.
Function to detect orphan documents
function orphanDocuments()
local documents = {}
-- search for all documents
local docResult = query[[from tags.document select _.name]] or {}
for name in docResult do
if name then
documents[name] = true
end
end
-- search for all links to documents
local relResult = query[[
from tags.relation
where _.toTag == "document"
select _.to
]] or {}
-- remove documents if linked
for target in relResult do
if target then
documents[target] = nil
end
end
local orphans = table.keys(documents)
table.sort(orphans)
if #orphans == 0 then
return "No orphan documents found"
end
-- Build a markdown list with wiki links
local lines = {}
for _, name in ipairs(orphans) do
table.insert(lines, "* [[" .. name .. "]] - " .. name)
end
return table.concat(lines, "\n")
end
List orphan documents
${orphanDocuments()}