According to the markdoc docs (https://markdoc.dev/docs/nodes#built-in-nodes), the node type document should store the frontmatter in an attribute called frontmatter (as shown in the sandbox https://markdoc.dev/sandbox?mode=ast)
However, I can't access it from the transform function:
nodes: {
document: {
render: null,
attributes: {
frontmatter: { type: String },
},
transform(node: Node, config: Config): RenderableTreeNode | RenderableTreeNode[] | null {
const children = node.transformChildren(config);
const attributes = node.transformAttributes(config);
console.log(node.attributes) // Prints empty object
console.log(attributes) // Prints empty object
console.log(config.variables?.entry.data) // Prints the frontmatter
return children
}
}
}
I have also tried to change the type of the attribute to Object, but no change. And if I add required: true I get a missing attribute error (failed to validate: attribute-missing-required).
I'm aware that I don't need to do that in the transform function (i.e. I can do it by parsing with Markdoc.parse(entry.body) the same way one would extract the headings)
Is it possible to modify the frontmatter in the transform function in a similar way one would use a remark plugin to do so?