2023-05-18 15:25:40 +02:00
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
import { useState } from 'react'
|
|
|
|
import { Spinner } from 'shared/components/spinner.mjs'
|
|
|
|
import { MdxWrapper } from './wrapper.mjs'
|
|
|
|
import { components } from 'shared/components/mdx/index.mjs'
|
|
|
|
|
2023-08-30 15:18:47 -05:00
|
|
|
const orgComponents = components()
|
2023-07-17 11:40:45 -05:00
|
|
|
export const loaders = {
|
|
|
|
en: (path) => import(`orgmarkdown/docs/${path}/en.md`),
|
|
|
|
de: (path) => import(`orgmarkdown/docs/${path}/de.md`),
|
|
|
|
fr: (path) => import(`orgmarkdown/docs/${path}/fr.md`),
|
|
|
|
es: (path) => import(`orgmarkdown/docs/${path}/es.md`),
|
|
|
|
nl: (path) => import(`orgmarkdown/docs/${path}/nl.md`),
|
|
|
|
uk: (path) => import(`orgmarkdown/docs/${path}/uk.md`),
|
|
|
|
}
|
2023-05-18 15:25:40 +02:00
|
|
|
/*
|
|
|
|
* Webpack will check on disk for all possible files matching this
|
|
|
|
* dynamic import. So unless we divide it up a bit your computer
|
|
|
|
* will melt when running this in development mode
|
|
|
|
*
|
|
|
|
* This will return a language-specific component
|
|
|
|
*/
|
|
|
|
|
2023-09-25 17:49:39 +02:00
|
|
|
function DynamicDocs({ path, lang, noFooter = false, noTitle = false }) {
|
2023-07-17 11:40:45 -05:00
|
|
|
const [frontmatter, setFrontmatter] = useState({})
|
|
|
|
const mdx = dynamic(
|
|
|
|
() =>
|
|
|
|
loaders[lang](path).then((mod) => {
|
|
|
|
setFrontmatter(mod.frontmatter)
|
|
|
|
return mod
|
|
|
|
}),
|
|
|
|
{ ssr: false }
|
|
|
|
)
|
|
|
|
const MDX = mdx ? mdx : <Spinner className="w16 h-16 animate-spin text-primary" />
|
2023-05-18 15:25:40 +02:00
|
|
|
|
2023-07-17 11:40:45 -05:00
|
|
|
return (
|
2023-09-25 17:49:39 +02:00
|
|
|
<MdxWrapper
|
|
|
|
path={path}
|
|
|
|
language={lang}
|
|
|
|
noFooter={noFooter}
|
|
|
|
title={noTitle ? false : frontmatter.title}
|
|
|
|
>
|
2023-08-30 15:18:47 -05:00
|
|
|
<MDX components={orgComponents} />
|
2023-07-17 11:40:45 -05:00
|
|
|
</MdxWrapper>
|
|
|
|
)
|
|
|
|
}
|
2023-05-18 15:25:40 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return language-specific component
|
|
|
|
*/
|
2023-09-25 17:49:39 +02:00
|
|
|
export const DynamicOrgDocs = ({
|
|
|
|
path = false,
|
|
|
|
language = 'en',
|
|
|
|
noTitle = false,
|
|
|
|
noFooter = false,
|
|
|
|
}) => {
|
2023-05-18 15:25:40 +02:00
|
|
|
if (!path) return null
|
2023-09-25 17:49:39 +02:00
|
|
|
return <DynamicDocs lang={language} {...{ path, noTitle, noFooter }} />
|
2023-05-18 15:25:40 +02:00
|
|
|
}
|