Compare commits
1 Commits
main
...
fix/low-me
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45b58d1d9a |
@@ -30,54 +30,43 @@ async function listAll<T>(fetchPage: (offset: number) => Promise<Page<T>>) {
|
||||
type Entry = { handle?: string | null; updated_at?: string | Date | null }
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const origin = await getSiteOrigin()
|
||||
const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
|
||||
|
||||
try {
|
||||
const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
|
||||
const [origin, regions, products, categories, collections] = await Promise.all([
|
||||
getSiteOrigin(),
|
||||
listRegions(),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.product
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.products, count: res.count }))
|
||||
),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.category
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.product_categories, count: res.count }))
|
||||
),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.collection
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.collections, count: res.count }))
|
||||
),
|
||||
])
|
||||
|
||||
const [regions, products, categories, collections] = await Promise.all([
|
||||
listRegions(),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.product
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.products, count: res.count }))
|
||||
),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.category
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({
|
||||
items: res.product_categories,
|
||||
count: res.count,
|
||||
}))
|
||||
),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.collection
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.collections, count: res.count }))
|
||||
),
|
||||
])
|
||||
const toEntries = (base: string, prefix: string, items: Entry[]) =>
|
||||
items
|
||||
.filter((item) => item.handle)
|
||||
.map((item) => ({
|
||||
url: `${base}/${prefix}/${item.handle}`,
|
||||
lastModified: item.updated_at ? new Date(item.updated_at) : undefined,
|
||||
}))
|
||||
|
||||
const toEntries = (base: string, prefix: string, items: Entry[]) =>
|
||||
items
|
||||
.filter((item) => item.handle)
|
||||
.map((item) => ({
|
||||
url: `${base}/${prefix}/${item.handle}`,
|
||||
lastModified: item.updated_at
|
||||
? new Date(item.updated_at)
|
||||
: undefined,
|
||||
}))
|
||||
|
||||
return listCountryCodes(regions).flatMap((countryCode) => {
|
||||
const base = `${origin}/${countryCode}`
|
||||
return [
|
||||
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
|
||||
...toEntries(base, "products", products),
|
||||
...toEntries(base, "categories", categories),
|
||||
...toEntries(base, "collections", collections),
|
||||
]
|
||||
})
|
||||
} catch {
|
||||
// During Docker build the backend is not running — return static paths only
|
||||
return STATIC_PATHS.map((path) => ({ url: `${origin}${path}` }))
|
||||
}
|
||||
return listCountryCodes(regions).flatMap((countryCode) => {
|
||||
const base = `${origin}/${countryCode}`
|
||||
return [
|
||||
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
|
||||
...toEntries(base, "products", products),
|
||||
...toEntries(base, "categories", categories),
|
||||
...toEntries(base, "collections", collections),
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,54 +30,43 @@ async function listAll<T>(fetchPage: (offset: number) => Promise<Page<T>>) {
|
||||
type Entry = { handle?: string | null; updated_at?: string | Date | null }
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const origin = await getSiteOrigin()
|
||||
const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
|
||||
|
||||
try {
|
||||
const query = { fields: "handle,updated_at", limit: PAGE_SIZE }
|
||||
const [origin, regions, products, categories, collections] = await Promise.all([
|
||||
getSiteOrigin(),
|
||||
listRegions(),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.product
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.products, count: res.count }))
|
||||
),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.category
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.product_categories, count: res.count }))
|
||||
),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.collection
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.collections, count: res.count }))
|
||||
),
|
||||
])
|
||||
|
||||
const [regions, products, categories, collections] = await Promise.all([
|
||||
listRegions(),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.product
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.products, count: res.count }))
|
||||
),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.category
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({
|
||||
items: res.product_categories,
|
||||
count: res.count,
|
||||
}))
|
||||
),
|
||||
listAll<Entry>((offset) =>
|
||||
sdk.store.collection
|
||||
.list({ ...query, offset })
|
||||
.then((res) => ({ items: res.collections, count: res.count }))
|
||||
),
|
||||
])
|
||||
const toEntries = (base: string, prefix: string, items: Entry[]) =>
|
||||
items
|
||||
.filter((item) => item.handle)
|
||||
.map((item) => ({
|
||||
url: `${base}/${prefix}/${item.handle}`,
|
||||
lastModified: item.updated_at ? new Date(item.updated_at) : undefined,
|
||||
}))
|
||||
|
||||
const toEntries = (base: string, prefix: string, items: Entry[]) =>
|
||||
items
|
||||
.filter((item) => item.handle)
|
||||
.map((item) => ({
|
||||
url: `${base}/${prefix}/${item.handle}`,
|
||||
lastModified: item.updated_at
|
||||
? new Date(item.updated_at)
|
||||
: undefined,
|
||||
}))
|
||||
|
||||
return listCountryCodes(regions).flatMap((countryCode) => {
|
||||
const base = `${origin}/${countryCode}`
|
||||
return [
|
||||
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
|
||||
...toEntries(base, "products", products),
|
||||
...toEntries(base, "categories", categories),
|
||||
...toEntries(base, "collections", collections),
|
||||
]
|
||||
})
|
||||
} catch {
|
||||
// During Docker build the backend is not running — return static paths only
|
||||
return STATIC_PATHS.map((path) => ({ url: `${origin}${path}` }))
|
||||
}
|
||||
return listCountryCodes(regions).flatMap((countryCode) => {
|
||||
const base = `${origin}/${countryCode}`
|
||||
return [
|
||||
...STATIC_PATHS.map((path) => ({ url: `${base}${path}` })),
|
||||
...toEntries(base, "products", products),
|
||||
...toEntries(base, "categories", categories),
|
||||
...toEntries(base, "collections", collections),
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user