1
0
Fork 0
freesewing/sites/org/pages/designs/[design].mjs

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-05-01 18:27:06 +02:00
// Dependencies
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
2023-09-25 18:00:38 +02:00
import { nsMerge } from 'shared/utils.mjs'
2023-09-25 17:49:39 +02:00
import { designList } from 'shared/config/designs.mjs'
import { siteConfig } from 'site/site.config.mjs'
// Hooks
import { useTranslation } from 'next-i18next'
2023-05-01 18:27:06 +02:00
// Components
import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs'
2023-09-25 17:49:39 +02:00
import { DesignInfo, ns as infoNs } from 'shared/components/designs/info.mjs'
2023-05-01 18:27:06 +02:00
// Translation namespaces used on this page
2023-09-25 17:49:39 +02:00
const ns = nsMerge(pageNs, infoNs)
2023-05-01 18:27:06 +02: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.
*/
2023-09-25 17:49:39 +02:00
const DesignsPage = ({ page, design }) => {
const { t } = useTranslation([...ns, design])
2023-05-01 18:27:06 +02:00
return (
2023-09-25 17:49:39 +02:00
<PageWrapper {...page} title={t(`designs:${design}.t`)}>
<DesignInfo design={design} />
2023-05-01 18:27:06 +02:00
</PageWrapper>
)
}
export default DesignsPage
export async function getStaticProps({ locale, params }) {
return {
props: {
2023-09-25 17:49:39 +02:00
...(await serverSideTranslations(locale, [...ns, params.design])),
design: params.design,
2023-05-01 18:27:06 +02:00
page: {
locale,
2023-09-25 17:49:39 +02:00
path: ['designs', params.design],
2023-05-01 18:27:06 +02:00
},
},
}
}
/*
* 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.
*
* To learn more, see: https://nextjs.org/docs/basic-features/data-fetching
*/
export async function getStaticPaths() {
2023-09-25 17:49:39 +02:00
const enPaths = [...designList].map((design) => `/designs/${design}`)
2023-05-01 18:27:06 +02:00
const paths = [...enPaths]
for (const lang of siteConfig.languages.filter((lang) => lang !== 'en')) {
paths.push(...enPaths.map((path) => `/${lang}${path}`))
}
return {
paths,
fallback: 'blocking',
}
}