1
0
Fork 0
freesewing/sites/org/pages/docs/[...slug].mjs

86 lines
2.7 KiB
JavaScript
Raw Normal View History

2023-09-04 08:40:05 +02:00
import { nsMerge } from 'shared/utils.mjs'
// Used in static paths
2023-07-20 08:52:50 +02:00
import { pages } from 'site/prebuild/docs.en.mjs'
// Dependencies
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
2023-10-07 21:19:38 +02:00
import { loadMdxAsStaticProps } from 'shared/mdx/load.mjs'
// Components
2023-07-17 11:40:45 -05:00
import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs'
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'
export const ns = nsMerge(pageNs, layoutNs, 'designs', 'account', 'tags')
2023-07-19 21:11:59 -06:00
/**
* A page to display documentation markdown
2023-07-19 21:11:59 -06:00
* Each page MUST be wrapped in the PageWrapper component.
* You also MUST spread props.page into this wrapper component
* when path and locale come from static props (as here)
* or set them manually.
*/
const Page = ({ page, locale, frontmatter, mdx, mdxSlug }) => (
<PageWrapper
{...page}
2023-07-17 12:17:23 -05:00
locale={locale}
title={frontmatter.title}
intro={frontmatter.intro || frontmatter.lead}
2023-07-17 11:40:45 -05:00
layout={(props) => <DocsLayout {...props} {...{ slug: page.path.join('/'), frontmatter }} />}
>
<MdxWrapper mdx={mdx} site="org" slug={mdxSlug} />
</PageWrapper>
)
export default Page
/*
* 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: {
2023-09-04 08:40:05 +02:00
...(await serverSideTranslations('en', ns)),
2023-10-07 21:19:38 +02:00
...(await loadMdxAsStaticProps({
language: locale,
site: 'org',
slug: `docs/${params.slug.join('/')}`,
})),
2023-07-17 11:40:45 -05:00
slug: params.slug.join('/'),
mdxSlug: params.slug,
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 = Object.keys(pages).filter((path) => path !== 'docs')
//.filter((path) => path.split('/').length < 5)
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}`),
2023-07-20 08:52:50 +02:00
...somePaths.map((key) => `/uk/${key}`),
],
2023-08-28 08:43:00 +02:00
fallback: false,
}
}