forked from crowetic/commerce
Merge pull request #48 from vercel/fix-pages
Update to latest Next.js canary and fix for custom web pages
This commit is contained in:
commit
19621632f5
26
lib/usage-warns.ts
Normal file
26
lib/usage-warns.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* The utils here are used to help developers use the example
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function missingLocaleInPages(): [string[], () => void] {
|
||||||
|
const invalidPaths: string[] = []
|
||||||
|
const log = () => {
|
||||||
|
if (invalidPaths.length) {
|
||||||
|
const single = invalidPaths.length === 1
|
||||||
|
const pages = single ? 'page' : 'pages'
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`The ${pages} "${invalidPaths.join(', ')}" ${
|
||||||
|
single ? 'does' : 'do'
|
||||||
|
} not include a locale, or the locale is not supported. 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]
|
||||||
|
}
|
@ -3,11 +3,9 @@ module.exports = {
|
|||||||
sizes: [320, 480, 820, 1200, 1600],
|
sizes: [320, 480, 820, 1200, 1600],
|
||||||
domains: ['cdn11.bigcommerce.com'],
|
domains: ['cdn11.bigcommerce.com'],
|
||||||
},
|
},
|
||||||
experimental: {
|
i18n: {
|
||||||
i18n: {
|
locales: ['en-US', 'es'],
|
||||||
locales: ['en-US', 'es'],
|
defaultLocale: 'en-US',
|
||||||
defaultLocale: 'en-US',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
rewrites() {
|
rewrites() {
|
||||||
return [
|
return [
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
"keen-slider": "^5.2.4",
|
"keen-slider": "^5.2.4",
|
||||||
"lodash.debounce": "^4.0.8",
|
"lodash.debounce": "^4.0.8",
|
||||||
"lodash.random": "^3.2.0",
|
"lodash.random": "^3.2.0",
|
||||||
"next": "^9.5.6-canary.17",
|
"next": "^10.0.1-canary.1",
|
||||||
"next-seo": "^4.11.0",
|
"next-seo": "^4.11.0",
|
||||||
"next-themes": "^0.0.4",
|
"next-themes": "^0.0.4",
|
||||||
"postcss-import": "^13.0.0",
|
"postcss-import": "^13.0.0",
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
import type {
|
||||||
|
GetStaticPathsContext,
|
||||||
|
GetStaticPropsContext,
|
||||||
|
InferGetStaticPropsType,
|
||||||
|
} from 'next'
|
||||||
import { getConfig } from '@bigcommerce/storefront-data-hooks/api'
|
import { getConfig } from '@bigcommerce/storefront-data-hooks/api'
|
||||||
import getPage from '@bigcommerce/storefront-data-hooks/api/operations/get-page'
|
import getPage from '@bigcommerce/storefront-data-hooks/api/operations/get-page'
|
||||||
import getAllPages from '@bigcommerce/storefront-data-hooks/api/operations/get-all-pages'
|
import getAllPages from '@bigcommerce/storefront-data-hooks/api/operations/get-all-pages'
|
||||||
import getSlug from '@lib/get-slug'
|
import getSlug from '@lib/get-slug'
|
||||||
|
import { missingLocaleInPages } from '@lib/usage-warns'
|
||||||
import { Layout, HTMLContent } from '@components/core'
|
import { Layout, HTMLContent } from '@components/core'
|
||||||
|
|
||||||
export async function getStaticProps({
|
export async function getStaticProps({
|
||||||
@ -32,11 +37,22 @@ export async function getStaticProps({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths({ locales }: GetStaticPathsContext) {
|
||||||
const { pages } = await getAllPages()
|
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 {
|
return {
|
||||||
paths: pages.map((page) => page.url).filter((url) => url),
|
paths,
|
||||||
// Fallback shouldn't be enabled here or otherwise this route
|
// Fallback shouldn't be enabled here or otherwise this route
|
||||||
// will catch every page, even 404s, and we don't want that
|
// will catch every page, even 404s, and we don't want that
|
||||||
fallback: false,
|
fallback: false,
|
||||||
|
48
yarn.lock
48
yarn.lock
@ -1132,20 +1132,20 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
webpack-bundle-analyzer "3.6.1"
|
webpack-bundle-analyzer "3.6.1"
|
||||||
|
|
||||||
"@next/env@9.5.6-canary.17":
|
"@next/env@10.0.1-canary.1":
|
||||||
version "9.5.6-canary.17"
|
version "10.0.1-canary.1"
|
||||||
resolved "https://registry.yarnpkg.com/@next/env/-/env-9.5.6-canary.17.tgz#d0289faee8ff5635973661580e3b2848add94534"
|
resolved "https://registry.yarnpkg.com/@next/env/-/env-10.0.1-canary.1.tgz#c49199b5dda48b7ef77cfc044fb2a38e6bc71e7d"
|
||||||
integrity sha512-O8noGIlyNHfhT/6oHePxfYAa3hNf4arRJ66RsSkodg4bAI4+tY5glOE8YZ+wn4q84Of6QVVh7R3tJzL8oK714w==
|
integrity sha512-f2OOhLRHym6WXKEngB+mwGxp48xQBY7sj2/N3s19zOp4HJn+4evKcq5lvtBL4N2K74L/ObCw1l/xTrruvk8WfQ==
|
||||||
|
|
||||||
"@next/polyfill-module@9.5.6-canary.17":
|
"@next/polyfill-module@10.0.1-canary.1":
|
||||||
version "9.5.6-canary.17"
|
version "10.0.1-canary.1"
|
||||||
resolved "https://registry.yarnpkg.com/@next/polyfill-module/-/polyfill-module-9.5.6-canary.17.tgz#c7c26939804b24d80151cc2af775e65ee97e3465"
|
resolved "https://registry.yarnpkg.com/@next/polyfill-module/-/polyfill-module-10.0.1-canary.1.tgz#ab97dce131db21dc70adeab552e01a20918f193f"
|
||||||
integrity sha512-zS5jmDwCiUpelp5BAc1e6vKSkKQkFHj53IhP+khkmDab48uv99iK32/qjNGurqyaHTbLjSXsPIGFmdKQ0hyE+A==
|
integrity sha512-/Kc9lXbDjGnGQogk9Hb5bYjx2031bXDnZVatBblzOt1cGapkiX8P5OOgnXv4ki17GtWW4/epPKzTfm2i3T9YPA==
|
||||||
|
|
||||||
"@next/react-dev-overlay@9.5.6-canary.17":
|
"@next/react-dev-overlay@10.0.1-canary.1":
|
||||||
version "9.5.6-canary.17"
|
version "10.0.1-canary.1"
|
||||||
resolved "https://registry.yarnpkg.com/@next/react-dev-overlay/-/react-dev-overlay-9.5.6-canary.17.tgz#0ad416c4d323fa013ee494f3fa3ac7e83bbc0c6b"
|
resolved "https://registry.yarnpkg.com/@next/react-dev-overlay/-/react-dev-overlay-10.0.1-canary.1.tgz#a54785d2aeab8fd76a25196eabc15ca281173c42"
|
||||||
integrity sha512-0fBLm2UNHpJKUhqecs95KxVWVQWvf0Xz9vs8G1J8hO8WMUkAEiuvOt6w9BG94a6/xL3tPzBF1B3t4q/k0YT7Dg==
|
integrity sha512-LEOcvJ+EjivrN2Ce2FSTUcb5VbyyQ4cVe/Ie/ja4+NzHIMMMX49nqTZ3uW4PIlfaGtCjiMZC8I43OgrMI2eG6w==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/code-frame" "7.10.4"
|
"@babel/code-frame" "7.10.4"
|
||||||
ally.js "1.4.1"
|
ally.js "1.4.1"
|
||||||
@ -1158,10 +1158,10 @@
|
|||||||
stacktrace-parser "0.1.10"
|
stacktrace-parser "0.1.10"
|
||||||
strip-ansi "6.0.0"
|
strip-ansi "6.0.0"
|
||||||
|
|
||||||
"@next/react-refresh-utils@9.5.6-canary.17":
|
"@next/react-refresh-utils@10.0.1-canary.1":
|
||||||
version "9.5.6-canary.17"
|
version "10.0.1-canary.1"
|
||||||
resolved "https://registry.yarnpkg.com/@next/react-refresh-utils/-/react-refresh-utils-9.5.6-canary.17.tgz#fb7ee8b51490187de72b27e0de5f9bd83ab2f310"
|
resolved "https://registry.yarnpkg.com/@next/react-refresh-utils/-/react-refresh-utils-10.0.1-canary.1.tgz#ce11b740fe80c4a43462a695247577bceb39a3db"
|
||||||
integrity sha512-Q2IU1MC8B9329WQQ1vZ/B3i7AcjBMQGcTCGf/QHRzzaqPa0zL90cCAksBCAxx5zbMv3BIJNrY+1VI+KYj5Po9A==
|
integrity sha512-9Q0LQ3NJxP6YbYhWyNYCUxlcT7EzwSYwDJ7j3dsDQt9dLwMC8PNmDVN38zpcqDMavb6jOFtbJMivef2ZylieKw==
|
||||||
|
|
||||||
"@npmcli/move-file@^1.0.1":
|
"@npmcli/move-file@^1.0.1":
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
@ -4305,10 +4305,10 @@ next-tick@~1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
|
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
|
||||||
integrity sha1-yobR/ogoFpsBICCOPchCS524NCw=
|
integrity sha1-yobR/ogoFpsBICCOPchCS524NCw=
|
||||||
|
|
||||||
next@^9.5.6-canary.17:
|
next@^10.0.1-canary.1:
|
||||||
version "9.5.6-canary.17"
|
version "10.0.1-canary.1"
|
||||||
resolved "https://registry.yarnpkg.com/next/-/next-9.5.6-canary.17.tgz#4ded8274457c05ac5028643fe9dfaf9f2808e300"
|
resolved "https://registry.yarnpkg.com/next/-/next-10.0.1-canary.1.tgz#fc68e0cfb04fce87dc81e8def09dc2cb916e106b"
|
||||||
integrity sha512-ocUNL44RA/0vD43uR91JBtfBvHwDlclqPkno+9un01XUw41ZJFn6aSd6VqiLFOZ5eCWk6lK5WbcfJiOH/aV1Rg==
|
integrity sha512-NG56oUFcX6AE+B8VFNXo6R1twWVGtj4037yNq+AI1zkQ3U7oWegZI+9KqjCi+4IzTvtl5tzkLvVxeaemEH+quA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@ampproject/toolbox-optimizer" "2.7.0-alpha.1"
|
"@ampproject/toolbox-optimizer" "2.7.0-alpha.1"
|
||||||
"@babel/code-frame" "7.10.4"
|
"@babel/code-frame" "7.10.4"
|
||||||
@ -4329,10 +4329,10 @@ next@^9.5.6-canary.17:
|
|||||||
"@babel/runtime" "7.11.2"
|
"@babel/runtime" "7.11.2"
|
||||||
"@babel/types" "7.11.5"
|
"@babel/types" "7.11.5"
|
||||||
"@hapi/accept" "5.0.1"
|
"@hapi/accept" "5.0.1"
|
||||||
"@next/env" "9.5.6-canary.17"
|
"@next/env" "10.0.1-canary.1"
|
||||||
"@next/polyfill-module" "9.5.6-canary.17"
|
"@next/polyfill-module" "10.0.1-canary.1"
|
||||||
"@next/react-dev-overlay" "9.5.6-canary.17"
|
"@next/react-dev-overlay" "10.0.1-canary.1"
|
||||||
"@next/react-refresh-utils" "9.5.6-canary.17"
|
"@next/react-refresh-utils" "10.0.1-canary.1"
|
||||||
ast-types "0.13.2"
|
ast-types "0.13.2"
|
||||||
babel-plugin-transform-define "2.0.0"
|
babel-plugin-transform-define "2.0.0"
|
||||||
babel-plugin-transform-react-remove-prop-types "0.4.24"
|
babel-plugin-transform-react-remove-prop-types "0.4.24"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user