forked from crowetic/commerce
Added locale to all pages
This commit is contained in:
parent
f54f830464
commit
c1d0395c4e
@ -1,4 +1,5 @@
|
|||||||
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||||
|
import { getConfig } from '@lib/bigcommerce/api'
|
||||||
import getPage from '@lib/bigcommerce/api/operations/get-page'
|
import getPage from '@lib/bigcommerce/api/operations/get-page'
|
||||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||||
import getSlug from '@utils/get-slug'
|
import getSlug from '@utils/get-slug'
|
||||||
@ -9,13 +10,15 @@ export async function getStaticProps({
|
|||||||
params,
|
params,
|
||||||
locale,
|
locale,
|
||||||
}: GetStaticPropsContext<{ pages: string[] }>) {
|
}: GetStaticPropsContext<{ pages: string[] }>) {
|
||||||
const { pages } = await getAllPages({ preview })
|
const config = getConfig({ locale })
|
||||||
|
const { pages } = await getAllPages({ preview, config })
|
||||||
const path = params?.pages.join('/')
|
const path = params?.pages.join('/')
|
||||||
const slug = locale ? `${locale}/${path}` : path
|
const slug = locale ? `${locale}/${path}` : path
|
||||||
|
|
||||||
const pageItem = pages.find((p) => (p.url ? getSlug(p.url) === slug : false))
|
const pageItem = pages.find((p) => (p.url ? getSlug(p.url) === slug : false))
|
||||||
const data =
|
const data =
|
||||||
pageItem && (await getPage({ variables: { id: pageItem.id! }, preview }))
|
pageItem &&
|
||||||
|
(await getPage({ variables: { id: pageItem.id! }, config, preview }))
|
||||||
const page = data?.page
|
const page = data?.page
|
||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
import type { GetStaticPropsContext } from 'next'
|
import type { GetStaticPropsContext } from 'next'
|
||||||
|
import { getConfig } from '@lib/bigcommerce/api'
|
||||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||||
import { Layout } from '@components/core'
|
import { Layout } from '@components/core'
|
||||||
import { Container } from '@components/ui'
|
import { Container } from '@components/ui'
|
||||||
|
|
||||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
export async function getStaticProps({
|
||||||
const { pages } = await getAllPages({ preview })
|
preview,
|
||||||
|
locale,
|
||||||
|
}: GetStaticPropsContext) {
|
||||||
|
const config = getConfig({ locale })
|
||||||
|
const { pages } = await getAllPages({ config, preview })
|
||||||
return {
|
return {
|
||||||
props: { pages },
|
props: { pages },
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type { GetStaticPropsContext } from 'next'
|
import type { GetStaticPropsContext } from 'next'
|
||||||
|
import { getConfig } from '@lib/bigcommerce/api'
|
||||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||||
import { Layout } from '@components/core'
|
import { Layout } from '@components/core'
|
||||||
import { Button } from '@components/ui'
|
import { Button } from '@components/ui'
|
||||||
@ -8,8 +9,12 @@ import usePrice from '@lib/bigcommerce/use-price'
|
|||||||
import { CartItem } from '@components/cart'
|
import { CartItem } from '@components/cart'
|
||||||
import { Text } from '@components/ui'
|
import { Text } from '@components/ui'
|
||||||
|
|
||||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
export async function getStaticProps({
|
||||||
const { pages } = await getAllPages({ preview })
|
preview,
|
||||||
|
locale,
|
||||||
|
}: GetStaticPropsContext) {
|
||||||
|
const config = getConfig({ locale })
|
||||||
|
const { pages } = await getAllPages({ config, preview })
|
||||||
return {
|
return {
|
||||||
props: { pages },
|
props: { pages },
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
import type { GetStaticPropsContext } from 'next'
|
import type { GetStaticPropsContext } from 'next'
|
||||||
|
import { getConfig } from '@lib/bigcommerce/api'
|
||||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||||
import { Layout } from '@components/core'
|
import { Layout } from '@components/core'
|
||||||
import { Container, Text } from '@components/ui'
|
import { Container, Text } from '@components/ui'
|
||||||
import { Bag } from '@components/icons'
|
import { Bag } from '@components/icons'
|
||||||
|
|
||||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
export async function getStaticProps({
|
||||||
const { pages } = await getAllPages({ preview })
|
preview,
|
||||||
|
locale,
|
||||||
|
}: GetStaticPropsContext) {
|
||||||
|
const config = getConfig({ locale })
|
||||||
|
const { pages } = await getAllPages({ config, preview })
|
||||||
return {
|
return {
|
||||||
props: { pages },
|
props: { pages },
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
import type { GetStaticPropsContext } from 'next'
|
import type { GetStaticPropsContext } from 'next'
|
||||||
|
import { getConfig } from '@lib/bigcommerce/api'
|
||||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||||
import useCustomer from '@lib/bigcommerce/use-customer'
|
import useCustomer from '@lib/bigcommerce/use-customer'
|
||||||
import { Layout } from '@components/core'
|
import { Layout } from '@components/core'
|
||||||
import { Container, Text } from '@components/ui'
|
import { Container, Text } from '@components/ui'
|
||||||
|
|
||||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
export async function getStaticProps({
|
||||||
const { pages } = await getAllPages({ preview })
|
preview,
|
||||||
|
locale,
|
||||||
|
}: GetStaticPropsContext) {
|
||||||
|
const config = getConfig({ locale })
|
||||||
|
const { pages } = await getAllPages({ config, preview })
|
||||||
return {
|
return {
|
||||||
props: { pages },
|
props: { pages },
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@ import cn from 'classnames'
|
|||||||
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
|
import { getConfig } from '@lib/bigcommerce/api'
|
||||||
|
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||||
|
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
|
||||||
|
import useSearch from '@lib/bigcommerce/products/use-search'
|
||||||
import { Layout } from '@components/core'
|
import { Layout } from '@components/core'
|
||||||
import { ProductCard } from '@components/product'
|
import { ProductCard } from '@components/product'
|
||||||
import { Container, Grid, Skeleton } from '@components/ui'
|
import { Container, Grid, Skeleton } from '@components/ui'
|
||||||
import useSearch from '@lib/bigcommerce/products/use-search'
|
|
||||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
|
||||||
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
|
|
||||||
import rangeMap from '@lib/range-map'
|
import rangeMap from '@lib/range-map'
|
||||||
import getSlug from '@utils/get-slug'
|
import getSlug from '@utils/get-slug'
|
||||||
import {
|
import {
|
||||||
@ -17,9 +19,13 @@ import {
|
|||||||
useSearchMeta,
|
useSearchMeta,
|
||||||
} from '@utils/search'
|
} from '@utils/search'
|
||||||
|
|
||||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
export async function getStaticProps({
|
||||||
const { pages } = await getAllPages({ preview })
|
preview,
|
||||||
const { categories, brands } = await getSiteInfo({ preview })
|
locale,
|
||||||
|
}: GetStaticPropsContext) {
|
||||||
|
const config = getConfig({ locale })
|
||||||
|
const { pages } = await getAllPages({ config, preview })
|
||||||
|
const { categories, brands } = await getSiteInfo({ config, preview })
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: { pages, categories, brands },
|
props: { pages, categories, brands },
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type { GetStaticPropsContext } from 'next'
|
import type { GetStaticPropsContext } from 'next'
|
||||||
|
import { getConfig } from '@lib/bigcommerce/api'
|
||||||
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
||||||
import useWishlist from '@lib/bigcommerce/wishlist/use-wishlist'
|
import useWishlist from '@lib/bigcommerce/wishlist/use-wishlist'
|
||||||
import { Layout } from '@components/core'
|
import { Layout } from '@components/core'
|
||||||
@ -6,9 +7,12 @@ import { Heart } from '@components/icons'
|
|||||||
import { Container, Text } from '@components/ui'
|
import { Container, Text } from '@components/ui'
|
||||||
import { WishlistCard } from '@components/wishlist'
|
import { WishlistCard } from '@components/wishlist'
|
||||||
|
|
||||||
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
export async function getStaticProps({
|
||||||
const { pages } = await getAllPages({ preview })
|
preview,
|
||||||
|
locale,
|
||||||
|
}: GetStaticPropsContext) {
|
||||||
|
const config = getConfig({ locale })
|
||||||
|
const { pages } = await getAllPages({ config, preview })
|
||||||
return {
|
return {
|
||||||
props: { pages },
|
props: { pages },
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user