mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Added locale metadata for products and product page
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||
import {
|
||||
GetStaticPathsContext,
|
||||
GetStaticPropsContext,
|
||||
InferGetStaticPropsType,
|
||||
} from 'next'
|
||||
import { useRouter } from 'next/router'
|
||||
import { getConfig } from '@lib/bigcommerce/api'
|
||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||
import getProduct from '@lib/bigcommerce/api/operations/get-product'
|
||||
import { Layout } from '@components/core'
|
||||
@@ -8,9 +13,15 @@ import getAllProductPaths from '@lib/bigcommerce/api/operations/get-all-product-
|
||||
|
||||
export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
}: GetStaticPropsContext<{ slug: string }>) {
|
||||
const { pages } = await getAllPages()
|
||||
const { product } = await getProduct({ variables: { slug: params!.slug } })
|
||||
const config = getConfig({ locale })
|
||||
|
||||
const { pages } = await getAllPages({ config })
|
||||
const { product } = await getProduct({
|
||||
variables: { slug: params!.slug },
|
||||
config,
|
||||
})
|
||||
|
||||
if (!product) {
|
||||
throw new Error(`Product with slug '${params!.slug}' not found`)
|
||||
@@ -22,11 +33,19 @@ export async function getStaticProps({
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
export async function getStaticPaths({ locales }: GetStaticPathsContext) {
|
||||
const { products } = await getAllProductPaths()
|
||||
|
||||
return {
|
||||
paths: products.map((product) => `/product${product.node.path}`),
|
||||
paths: locales
|
||||
? locales.reduce<string[]>((arr, locale) => {
|
||||
// Add a product path for every locale
|
||||
products.forEach((product) => {
|
||||
arr.push(`/${locale}/product${product.node.path}`)
|
||||
})
|
||||
return arr
|
||||
}, [])
|
||||
: products.map((product) => `/product${product.node.path}`),
|
||||
// If your store has tons of products, enable fallback mode to improve build times!
|
||||
fallback: false,
|
||||
}
|
||||
|
Reference in New Issue
Block a user