there already is a functions to strip a text from its frontmatter API/index Documentation
index.extractFrontmatter(text, extractOptions)
To strip a frontmatter from a page:
function strip_frontmatter_page(page)
local fm = index.extractFrontmatter(space.readPage(page), {
removeFrontMatterSection = true,
removeTags = false
})
return fm.text
end
To strip frontmatter from a text
function strip_frontmatter_from_text(text)
local fm = index.extractFrontmatter(text, {
removeFrontMatterSection = true,
removeTags = false
})
return "Text without frontmatter: " .. fm.text .."\n\nAnd this is the frontmatter:" .. fm.frontmatter
end
here is a screenshot with the result for fm
