feat(fs.dev): Loading MDX is now ok
This commit is contained in:
parent
092c81f535
commit
c5e971e8a7
11 changed files with 231 additions and 49 deletions
33
packages/freesewing.shared/mdx/loader.js
Normal file
33
packages/freesewing.shared/mdx/loader.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
// We need fs and path to read from disk
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
// MDX compiler
|
||||
import { compile } from '@mdx-js/mdx'
|
||||
|
||||
/*
|
||||
* Summary: Loads markdown from disk and compiles it as MDX.
|
||||
*
|
||||
* @param (string) language - language to load (eg: 'en')
|
||||
* @param (string) site - site to load (either 'dev' or 'org')
|
||||
* @param (string) slug - slug of the page (eg: 'guides/patterns')
|
||||
*
|
||||
* @link https://mdxjs.com/guides/mdx-on-demand/
|
||||
*
|
||||
*/
|
||||
const mdxLoader = async (language, site, slug) => {
|
||||
|
||||
// TODO: Will this work on Windows?
|
||||
const md = await fs.promises.readFile(
|
||||
path.resolve(`../../markdown/${site}/${slug}/${language}.md`),
|
||||
'utf-8'
|
||||
)
|
||||
|
||||
const mdx = String(
|
||||
await compile(md, { outputFormat: 'function-body' })
|
||||
)
|
||||
|
||||
return mdx
|
||||
}
|
||||
|
||||
export default mdxLoader
|
Loading…
Add table
Add a link
Reference in a new issue