In V1 there was an option to configure page decorations based on page attributes globally (still present in the v2 docs: Page Decorations).
I’m thinking, how could we achieve the same effect with V2. Do you guys have any ideas?
In V1 there was an option to configure page decorations based on page attributes globally (still present in the v2 docs: Page Decorations).
I’m thinking, how could we achieve the same effect with V2. Do you guys have any ideas?
Yes, my plan for this is to use Lua metatables. This already kind of works, just not for the page decoration use case . It’s undocumented, but sharing here so you can try.
This is my test page:
```space-lua
local mt = {
__index = function(self, attr)
if attr == "pageDecoration" then
return {
prefix = "🎄 "
}
end
end
}
index.defineTag {
name = "tree",
metatable = mt
}
```
#tree
Sup
${query[[from index.tag "tree" select {name=name, pageDecoration=_.pageDecoration}]]}
You’ll see that in the query result the pageDecoration
attribute is dynamically injected. However, since all the uses of pageDecorations in the UI happen across plug boundaries, this ability of using metatables gets lost. I have to figure out how to work around that.
By the way, I also intend to add a schema
attribute to that defineTag
call with an (optional) JSON schema, which can then be used to bring back the v1 schema feature, which can validate frontmatter, be used for attribute completion etc.
I can’t seem to get it to work, so until it does, I’m just trying to create a set of functions that would update the page decoration “in place”.
And my problem is… there is no good API for changing the frontmatter of the note (or I cannot find it).
I’ve noticed that the closest to what I want (actually almost exactly) is the index.patchFrontmatter
function BUT… it doesn’t work properly for me.
When my frontmatter is:
---
pageDecoration:
prefix: "X"
---
and I do:
local page = space.readPage(myPage)
local updatedPage = index.patchFrontmatter(page, {
{ op="set-key", path = "pageDecoration", value = { prefix = "Y" }}
}
space.writePage(myPage, updatedPage)
it doesn’t remove the prefix: X
so now my frontmatter looks like this:
---
pageDecoration:
prefix: "Y"
prefix: "X"
---
I think that the implementation here only supports changing a single line value, but I’m not sure (didn’t really look into it, as I’m not very fluent in TypeScript).
Is there any other API for actually changing the frontmatter of a file?
This should be the one and it should work as you are using it. This is the feature I AI coded in this video: https://youtu.be/hmSsFVPmHKA
It looks like I have to add more edge cases to the test suite to handle this one too.
Hey! It’s kind of related here. I couldn’t come up with a way to remove the linked mentions from a page in V2 since the widgets are read-only. Is there any ideas for it?