forked from crowetic/commerce
Improved log and moved out of the page
This commit is contained in:
parent
7c9be7cf73
commit
c70a965c7d
22
lib/usage-warns.ts
Normal file
22
lib/usage-warns.ts
Normal file
@ -0,0 +1,22 @@
|
||||
export function missingLocaleInPages(): [string[], () => void] {
|
||||
const invalidPaths: string[] = []
|
||||
const log = () => {
|
||||
if (invalidPaths.length) {
|
||||
const single = invalidPaths.length === 0
|
||||
const pages = single ? 'page' : 'pages'
|
||||
|
||||
console.log(
|
||||
`The ${pages} "${invalidPaths.join(', ')}" ${
|
||||
single ? 'does' : 'do'
|
||||
} not include a locale, when using i18n web pages from BigCommerce
|
||||
are expected to have a locale or they will be ignored.\n
|
||||
Please update the ${pages} to include the default locale or make the ${pages} invisible by
|
||||
unchecking the "Navigation Menu" option in the settings of ${
|
||||
single ? 'the' : 'each'
|
||||
} web page\n`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return [invalidPaths, log]
|
||||
}
|
@ -8,6 +8,7 @@ import getPage from '@bigcommerce/storefront-data-hooks/api/operations/get-page'
|
||||
import getAllPages from '@bigcommerce/storefront-data-hooks/api/operations/get-all-pages'
|
||||
import getSlug from '@lib/get-slug'
|
||||
import { Layout, HTMLContent } from '@components/core'
|
||||
import { missingLocaleInPages } from '@lib/usage-warns'
|
||||
|
||||
export async function getStaticProps({
|
||||
preview,
|
||||
@ -38,19 +39,20 @@ export async function getStaticProps({
|
||||
|
||||
export async function getStaticPaths({ locales }: GetStaticPathsContext) {
|
||||
const { pages } = await getAllPages()
|
||||
const [invalidPaths, log] = missingLocaleInPages()
|
||||
const paths = pages
|
||||
.map((page) => page.url)
|
||||
.filter((url) => {
|
||||
if (!url || !locales) return url
|
||||
// If there are locales, only include the pages that include one of the available locales
|
||||
if (locales.includes(getSlug(url).split('/')[0])) return url
|
||||
|
||||
invalidPaths.push(url)
|
||||
})
|
||||
log()
|
||||
|
||||
return {
|
||||
paths: pages
|
||||
.map((page) => page.url)
|
||||
.filter((url) => {
|
||||
if (!locales) return url
|
||||
// If there are locales, only include the pages that include one of the available locales
|
||||
if (url && locales.includes(getSlug(url).split('/')[0])) return url
|
||||
|
||||
console.log(
|
||||
`The page '${url}' does not include a locale, when using i18n web pages from BigCommerce are expected to have a locale or they will be ignored`
|
||||
)
|
||||
}),
|
||||
paths,
|
||||
// Fallback shouldn't be enabled here or otherwise this route
|
||||
// will catch every page, even 404s, and we don't want that
|
||||
fallback: false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user