// __SDEFILE__ - This file is a dependency for the stand-alone environment
// Dependencies
import { compileMdx } from 'shared/mdx/browser-compile.mjs'
import * as runtime from 'react/jsx-runtime'
import { run } from '@mdx-js/mdx'
// Hooks
import { useState, useEffect } from 'react'
// Components
import { MdxWrapper } from 'shared/components/wrappers/mdx.mjs'
import { Loading } from 'shared/components/spinner.mjs'
const ghPrefix = 'https://raw.githubusercontent.com/freesewing/freesewing/develop/markdown'
const fromGithub = true
const titles = {
1: ({ title }) =>
{title}
,
2: ({ title }) => {title}
,
3: ({ title }) => {title}
,
4: ({ title }) => {title}
,
5: ({ title }) => {title}
,
6: ({ title }) => {title}
,
}
export const DynamicMdx = ({ site = 'org', slug, language, title = 1 }) => {
const [mdx, setMdx] = useState(false)
const [frontmatter, setFrontmatter] = useState(false)
useEffect(() => {
const loadMdx = async () => {
const response = await fetch(`${ghPrefix}/${site}/${slug}/${language}.md`)
const md = await response.text()
const mdx = await compileMdx({ site, slug, language, md, fromGithub })
const { frontmatter: fm } = await run(mdx, runtime)
setMdx(mdx)
setFrontmatter(fm)
}
if (!mdx) loadMdx()
}, [site, slug, language])
const Title = title && frontmatter?.title && titles[Number(title)] ? titles[title] : () => null
return mdx ? (
<>
>
) : (
)
}
export const Mdx = ({ md }) => {
const [mdx, setMdx] = useState(false)
useEffect(() => {
const loadMdx = async () => {
try {
const mdx = await compileMdx({ md })
setMdx(mdx)
} catch (err) {
console.log(err)
}
}
loadMdx()
}, [md])
return mdx ? :
}