@mintlify/common
Version:
Commonly shared code within Mintlify
12 lines (11 loc) • 497 B
JavaScript
import matter from 'gray-matter';
const { test: hasFrontmatter } = matter;
/**
* Injects content to the top of a file, but below the frontmatter
*/
export const injectToTopOfFile = (content, contentToInject) => {
if (!hasFrontmatter(content))
return contentToInject + `\n` + content;
const { data: frontmatterData, content: contentWithoutFrontmatter } = matter(content);
return matter.stringify(`\n` + contentToInject + `\n` + contentWithoutFrontmatter, frontmatterData);
};