[examples/data-literate][m]: factor our a working markdown+CSV (data literate) example from site (where we already had a demo).

* removed a few extraneous things
* added the README.md with some instructions
This commit is contained in:
Rufus Pollock
2022-02-21 12:25:46 +01:00
parent 99c5e358a1
commit 3a0f4e7b96
22 changed files with 5817 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import matter from 'gray-matter'
import toc from 'remark-toc'
import slug from 'remark-slug'
import gfm from 'remark-gfm'
import footnotes from 'remark-footnotes'
import { serialize } from 'next-mdx-remote/serialize'
/**
* Parse a markdown or MDX file to an MDX source form + front matter data
*
* @source: the contents of a markdown or mdx file
* @returns: { mdxSource: mdxSource, frontMatter: ...}
*/
const parse = async function(source) {
const { content, data } = matter(source)
const mdxSource = await serialize(content, {
// Optionally pass remark/rehype plugins
mdxOptions: {
remarkPlugins: [gfm, toc, slug, footnotes],
rehypePlugins: [],
},
scope: data,
})
return {
mdxSource: mdxSource,
frontMatter: data
}
}
export default parse