Add preview where applicable

This commit is contained in:
Luis Alvarez
2020-10-27 00:47:29 -05:00
parent 3e7b1f833f
commit c9b4a9ad4c
14 changed files with 57 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
import getSlug from '@utils/get-slug'
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
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'
import { Layout, HTMLContent } from '@components/core'
export async function getStaticProps({
@@ -9,12 +9,13 @@ export async function getStaticProps({
params,
locale,
}: GetStaticPropsContext<{ pages: string[] }>) {
const { pages } = await getAllPages()
const { pages } = await getAllPages({ preview })
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 data =
pageItem && (await getPage({ variables: { id: pageItem.id! }, preview }))
const page = data?.page
if (!page) {