Implement getAllProductPaths to prerender some products during build time

This commit is contained in:
tniezg
2021-08-19 14:02:13 +02:00
parent ed49ac8833
commit a191e28df7
5 changed files with 123 additions and 13 deletions

View File

@@ -0,0 +1,7 @@
import type { ProductSlugAttr } from '@framework/types'
const getProductPath = (partialSpreeProduct: ProductSlugAttr): string => {
return `/${partialSpreeProduct.attributes.slug}`
}
export default getProductPath

View File

@@ -15,6 +15,7 @@ import createGetAbsoluteImageUrl from './create-get-absolute-image-url'
import expandOptions from './expand-options'
import getMediaGallery from './get-media-gallery'
import { findIncludedOfType } from './find-json-api-documents'
import getProductPath from './get-product-path'
const normalizeProduct = (
spreeSuccessResponse: JsonApiSingleResponse | JsonApiListResponse,
@@ -82,7 +83,7 @@ const normalizeProduct = (
})
const slug = spreeProduct.attributes.slug
const path = `/${spreeProduct.attributes.slug}`
const path = getProductPath(spreeProduct)
return {
id: spreeProduct.id,

View File

@@ -0,0 +1,21 @@
const validateProductsPrerenderCount = (prerenderCount: unknown): number => {
let prerenderCountInteger: number
if (typeof prerenderCount === 'string') {
prerenderCountInteger = parseInt(prerenderCount)
} else if (typeof prerenderCount === 'number') {
prerenderCountInteger = prerenderCount
} else {
throw new TypeError(
'prerenderCount count must be a string containing a number or an integer.'
)
}
if (prerenderCountInteger < 0) {
throw new RangeError('prerenderCount must be non-negative.')
}
return prerenderCountInteger
}
export default validateProductsPrerenderCount