@mintlify/common
Version:
Commonly shared code within Mintlify
18 lines (17 loc) • 671 B
JavaScript
/**
* Injects nodes to the top of a MDX/Markdown AST (Root), but below the frontmatter (YAML node).
* Modifies the tree in place.
* @param tree The Root node of the document.
* @param nodesToInject An array of RootContent nodes to inject.
*/
export const injectToTopOfFileOfTree = (tree, nodesToInject) => {
const firstChild = tree.children[0];
if ((firstChild === null || firstChild === void 0 ? void 0 : firstChild.type) === 'yaml') {
// Insert after the frontmatter (yaml node)
tree.children.splice(1, 0, ...nodesToInject);
}
else {
// Insert at the very beginning
tree.children.unshift(...nodesToInject);
}
};