forked from crowetic/commerce
Use parallel fetches for sitemap requests and remove duplicate /search url (#1004)
Co-authored-by: Andrew Jones <andrewj@corra.com> Co-authored-by: Lee Robinson <lrobinson2011@gmail.com>
This commit is contained in:
parent
23d15496d1
commit
a5e799b16e
@ -6,28 +6,35 @@ const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL
|
|||||||
: 'http://localhost:3000';
|
: 'http://localhost:3000';
|
||||||
|
|
||||||
export default async function sitemap(): Promise<Promise<Promise<MetadataRoute.Sitemap>>> {
|
export default async function sitemap(): Promise<Promise<Promise<MetadataRoute.Sitemap>>> {
|
||||||
const routesMap = ['', '/search'].map((route) => ({
|
const routesMap = [''].map((route) => ({
|
||||||
url: `${baseUrl}${route}`,
|
url: `${baseUrl}${route}`,
|
||||||
lastModified: new Date().toISOString()
|
lastModified: new Date().toISOString()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const collections = await getCollections();
|
const collectionsPromise = getCollections().then((collections) =>
|
||||||
const collectionsMap = collections.map((collection) => ({
|
collections.map((collection) => ({
|
||||||
url: `${baseUrl}${collection.path}`,
|
url: `${baseUrl}${collection.path}`,
|
||||||
lastModified: collection.updatedAt
|
lastModified: collection.updatedAt
|
||||||
}));
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
const products = await getProducts({});
|
const productsPromise = getProducts({}).then((products) =>
|
||||||
const productsMap = products.map((product) => ({
|
products.map((product) => ({
|
||||||
url: `${baseUrl}/product/${product.handle}`,
|
url: `${baseUrl}/product/${product.handle}`,
|
||||||
lastModified: product.updatedAt
|
lastModified: product.updatedAt
|
||||||
}));
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
const pages = await getPages();
|
const pagesPromise = getPages().then((pages) =>
|
||||||
const pagesMap = pages.map((page) => ({
|
pages.map((page) => ({
|
||||||
url: `${baseUrl}/${page.handle}`,
|
url: `${baseUrl}/${page.handle}`,
|
||||||
lastModified: page.updatedAt
|
lastModified: page.updatedAt
|
||||||
}));
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
return [...routesMap, ...collectionsMap, ...productsMap, ...pagesMap];
|
const fetchedRoutes = (
|
||||||
|
await Promise.all([collectionsPromise, productsPromise, pagesPromise])
|
||||||
|
).flat();
|
||||||
|
|
||||||
|
return [...routesMap, ...fetchedRoutes];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user