feat(poc): improve sitemap a bit

This commit is contained in:
Björn Meyer 2023-08-04 15:26:36 +02:00
parent 9855dfe88e
commit 3f66c391c1

View File

@ -1,4 +1,4 @@
import { getProductSeoUrls } from 'lib/shopware'; import { getProductSeoUrls, getMenu } from 'lib/shopware';
import { MetadataRoute } from 'next'; import { MetadataRoute } from 'next';
type Route = { type Route = {
@ -16,7 +16,21 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
lastModified: new Date().toISOString() lastModified: new Date().toISOString()
})); }));
// @ToDo: Get categories and get cms pages const mainNavigationPromise = getMenu({ type: 'main-navigation' }).then((mainNavigation) =>
mainNavigation.map((mainNavigationItem) => ({
url: `${baseUrl}${mainNavigationItem.path}`,
lastModified: new Date().toISOString()
}))
);
const footerNaivgationPromise = getMenu({ type: 'footer-navigation', depth: 2 }).then(
(footerNavigation) =>
footerNavigation.map((footerNavigationItem) => ({
url: `${baseUrl}${footerNavigationItem.path}`,
lastModified: new Date().toISOString()
}))
);
// @ToDo: currently this points to variants, would be better to point to parent products
const productsPromise = getProductSeoUrls().then((products) => const productsPromise = getProductSeoUrls().then((products) =>
products.map((product) => ({ products.map((product) => ({
url: `${baseUrl}/product/${product.path}`, url: `${baseUrl}/product/${product.path}`,
@ -27,7 +41,9 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
let fetchedRoutes: Route[] = []; let fetchedRoutes: Route[] = [];
try { try {
fetchedRoutes = (await Promise.all([productsPromise])).flat(); fetchedRoutes = (
await Promise.all([productsPromise, mainNavigationPromise, footerNaivgationPromise])
).flat();
} catch (error) { } catch (error) {
throw JSON.stringify(error, null, 2); throw JSON.stringify(error, null, 2);
} }