Added locale to all pages

This commit is contained in:
Luis Alvarez
2020-10-27 04:00:42 -05:00
parent f54f830464
commit c1d0395c4e
7 changed files with 52 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
import { getConfig } from '@lib/bigcommerce/api'
import getPage from '@lib/bigcommerce/api/operations/get-page'
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
import getSlug from '@utils/get-slug'
@@ -9,13 +10,15 @@ export async function getStaticProps({
params,
locale,
}: GetStaticPropsContext<{ pages: string[] }>) {
const { pages } = await getAllPages({ preview })
const config = getConfig({ locale })
const { pages } = await getAllPages({ preview, config })
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! }, preview }))
pageItem &&
(await getPage({ variables: { id: pageItem.id! }, config, preview }))
const page = data?.page
if (!page) {