#apidoc
The index
API provides functions for interacting with SilverBullet's Objects, allowing you to store and query page-associated data.
Returns a given Objects#Tags as a query collection, to be queried using Space Lua/Lua Integrated Query.
Example:
${queryfrom index.tag("page") limit 1 limit 1)}
Indexes an array of objects for a specific page.
Example:
local objects = {
{tag = "mytask", ref="task1", content = "Buy groceries"},
{tag = "mytask", ref="task2", content = "Write docs"}
}
index.indexObjects("my page", objects)
Queries objects using a Lua-based collection query.
Example:
local tasks = index.queryLuaObjects("mytask", {limit=3})
Retrieves a specific object by its reference.
Example:
local task = index.getObjectByRef("my page", "mytask", "task1")
if task then
print("Found task: " .. task.content)
end
Extracts frontmatter from a markdown document (whose text is provided as argument), possibly cleaning it up. It also parses top-level tags consistent with SilverBullet's tag indexing system.
It returns a table with two keys:
- frontmatter
: A table containing the parsed frontmatter.
- text
: The text of the document, with any changes applied requested with the extractOptions
.
The extractOptions
is an optional table that can contain the following keys (which will affect the returned text
):
- removeKeys
: An array of keys to remove from the frontmatter.
- removeTags
: A boolean or array of tags to remove from the frontmatter.
- removeFrontMatterSection
: A boolean to remove the frontmatter section from the document.
Example applied to this page: ${(index.extractFrontmatter(editor.getText())).frontmatter}
Allows you to attach a custom Lua metatable to objects part of a particular tag.
The following adds a custom attribute to all page objects that dynamically produces an ALL CAPS version of the page name:
index.defineTag {
name = "page",
metatable = {
__index = function(self, attr)
if attr == "loudName" then
return string.upper(self.name)
end
end
}
}
In use: ${queryfrom index.tag "page" select {name=.name, loudName=.loudName} limit 3}