2023-05-20 14:06:39 +02:00
|
|
|
// Used in static paths
|
2023-05-21 20:06:19 +02:00
|
|
|
import { mdxPaths } from 'site/prebuild/mdx-paths.en.mjs'
|
2023-05-20 14:06:39 +02:00
|
|
|
// Dependencies
|
|
|
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
|
|
|
// Hooks
|
2023-07-18 23:14:09 -06:00
|
|
|
import { useCallback } from 'react'
|
2023-07-17 20:10:08 -05:00
|
|
|
import { useDynamicMdx } from 'shared/hooks/use-dynamic-mdx.mjs'
|
2023-05-20 14:06:39 +02:00
|
|
|
// Components
|
2023-07-17 11:40:45 -05:00
|
|
|
import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs'
|
2023-05-20 14:06:39 +02:00
|
|
|
import { MdxWrapper } from 'shared/components/wrappers/mdx.mjs'
|
2023-07-17 11:40:45 -05:00
|
|
|
import { DocsLayout, ns as layoutNs } from 'site/components/layouts/docs.mjs'
|
2023-07-17 20:10:08 -05:00
|
|
|
import { loaders } from 'shared/components/dynamic-docs/org.mjs'
|
2023-05-20 14:06:39 +02:00
|
|
|
|
2023-07-17 11:40:45 -05:00
|
|
|
const ns = [...pageNs, layoutNs]
|
2023-05-20 14:06:39 +02:00
|
|
|
/*
|
|
|
|
* PLEASE READ THIS BEFORE YOU TRY TO REFACTOR THIS PAGE
|
|
|
|
*
|
|
|
|
* You will notice that this page has a page component for each language
|
|
|
|
* and that those components are 95% identical. So you may be thinking:
|
|
|
|
*
|
|
|
|
* This is not DRY, let me refactor this real quick
|
|
|
|
*
|
|
|
|
* Before you do so, please reflect on these topics:
|
|
|
|
*
|
|
|
|
* - Do you know the pitfalls of dynamic imports in Webpack?
|
|
|
|
* - Do you know how much documentation we have?
|
|
|
|
* - Do you know we support 5 languages?
|
|
|
|
*
|
|
|
|
* If you do know all of these thigns, and you think you can improve this page. Go ahead.
|
|
|
|
*
|
|
|
|
* If you are not sure, then I would recommend you find something else to work on, unless
|
|
|
|
* you consider this a learning opportunity.
|
|
|
|
*
|
|
|
|
* joost
|
|
|
|
*
|
|
|
|
*/
|
2023-07-18 23:14:09 -06:00
|
|
|
export const Page = ({ page, locale, frontmatter, MDX }) => (
|
2023-07-15 16:55:22 +02:00
|
|
|
<PageWrapper
|
|
|
|
{...page}
|
2023-07-17 12:17:23 -05:00
|
|
|
locale={locale}
|
2023-07-15 16:55:22 +02:00
|
|
|
title={frontmatter.title}
|
2023-07-17 11:40:45 -05:00
|
|
|
layout={(props) => <DocsLayout {...props} {...{ slug: page.path.join('/'), frontmatter }} />}
|
2023-07-15 16:55:22 +02:00
|
|
|
>
|
2023-07-17 11:40:45 -05:00
|
|
|
<MdxWrapper>{MDX}</MdxWrapper>
|
2023-05-20 14:06:39 +02:00
|
|
|
</PageWrapper>
|
|
|
|
)
|
|
|
|
|
2023-07-17 20:10:08 -05:00
|
|
|
const DocsPage = ({ page, locale, slug }) => {
|
|
|
|
const loader = useCallback(() => loaders[locale](slug), [locale, slug])
|
2023-05-20 14:06:39 +02:00
|
|
|
// State
|
2023-07-17 20:10:08 -05:00
|
|
|
const { frontmatter, MDX } = useDynamicMdx(loader)
|
2023-05-20 14:06:39 +02:00
|
|
|
|
2023-07-17 20:10:08 -05:00
|
|
|
return <Page {...{ page, slug, frontmatter, MDX, locale }} />
|
2023-05-20 14:06:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default DocsPage
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getStaticProps() is used to fetch data at build-time.
|
|
|
|
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
|
|
|
|
*/
|
|
|
|
export async function getStaticProps({ locale, params }) {
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
...(await serverSideTranslations('en', ['docs', ...ns])),
|
2023-07-17 11:40:45 -05:00
|
|
|
slug: params.slug.join('/'),
|
2023-05-20 14:06:39 +02:00
|
|
|
locale,
|
|
|
|
page: {
|
|
|
|
locale,
|
|
|
|
path: ['docs', ...params.slug],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getStaticPaths() is used to specify for which routes (think URLs)
|
|
|
|
* this page should be used to generate the result.
|
|
|
|
*
|
|
|
|
* On this page, it is returning a list of routes (think URLs) for all
|
|
|
|
* the mdx (markdown) content.
|
|
|
|
* That list comes from mdxMeta, which is build in the prebuild step
|
|
|
|
* and contains paths, titles, and intro for all markdown.
|
|
|
|
*
|
|
|
|
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
|
|
|
|
*/
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
const somePaths = mdxPaths
|
|
|
|
.filter((path) => path.split('/').length < 5)
|
|
|
|
.filter((path) => path !== 'docs')
|
|
|
|
|
|
|
|
return {
|
|
|
|
paths: [
|
|
|
|
...somePaths.map((key) => `/${key}`),
|
|
|
|
...somePaths.map((key) => `/es/${key}`),
|
|
|
|
...somePaths.map((key) => `/de/${key}`),
|
|
|
|
...somePaths.map((key) => `/fr/${key}`),
|
|
|
|
...somePaths.map((key) => `/nl/${key}`),
|
|
|
|
],
|
|
|
|
fallback: 'blocking',
|
|
|
|
}
|
|
|
|
}
|