Added i18n for custom pages

This commit is contained in:
Luis Alvarez
2020-10-25 13:31:12 -05:00
parent e9092a4031
commit 7bc2c408ee
6 changed files with 64 additions and 47 deletions

View File

@@ -7,19 +7,24 @@ import { Layout, HTMLContent } from '@components/core'
export async function getStaticProps({
preview,
params,
locale,
}: GetStaticPropsContext<{ pages: string[] }>) {
const { pages } = await getAllPages()
const slug = params?.pages.join('/')
const path = params?.pages.join('/')
const slug = locale ? `${locale}/${path}` : path
const pageItem = pages.find((p) => (p.url ? getSlug(p.url) === slug : false))
const data = pageItem && (await getPage({ variables: { id: pageItem.id! } }))
const page = data?.page
if (!page) {
// We throw to make sure this fails at build time as this is never expected to happen
throw new Error(`Page with slug '${slug}' not found`)
}
return {
props: { pages, page },
revalidate: 60 * 60, // Every hour
}
}