-
I have .md file with frontmatter. How it should be parsed so that I got first as js object and second as html? Example: ---
title: Title
---
# This is a heading Usage: const {frontmatter: { title }, html} = // ? Docs seem to be very frustrating (softly speaking). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Welcome @gentlee! 👋 To your direct question:
|
Beta Was this translation helpful? Give feedback.
-
@ChristianMurphy syntax trees are trivial, problem is in API and docs. Finally managed to get that, thanks, this is how: import remarkExtractFrontmatter from 'remark-extract-frontmatter'
import remarkFrontmatter from 'remark-frontmatter'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'
import yaml from 'yaml'
const parsedArticle = await unified()
.use(remarkParse)
.use(remarkFrontmatter)
.use(remarkExtractFrontmatter, { yaml: yaml.parse, remove: true })
.use(remarkRehype)
.use(rehypeStringify)
.process(await fs.readFile(`article.md`, 'utf-8'))
const frontmatter = parsedArticle.data
const articleHtml = parsedArticle.toString() |
Beta Was this translation helpful? Give feedback.
@ChristianMurphy syntax trees are trivial, problem is in API and docs.
Finally managed to get that, thanks, this is how: