From 3f66c391c1f3ce002f2ae9ec3e7538eb6f2aca22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Meyer?= Date: Fri, 4 Aug 2023 15:26:36 +0200 Subject: [PATCH] feat(poc): improve sitemap a bit --- app/sitemap.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/sitemap.ts b/app/sitemap.ts index 06fe7306a..60b6393c1 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -1,4 +1,4 @@ -import { getProductSeoUrls } from 'lib/shopware'; +import { getProductSeoUrls, getMenu } from 'lib/shopware'; import { MetadataRoute } from 'next'; type Route = { @@ -16,7 +16,21 @@ export default async function sitemap(): Promise { 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) => products.map((product) => ({ url: `${baseUrl}/product/${product.path}`, @@ -27,7 +41,9 @@ export default async function sitemap(): Promise { let fetchedRoutes: Route[] = []; try { - fetchedRoutes = (await Promise.all([productsPromise])).flat(); + fetchedRoutes = ( + await Promise.all([productsPromise, mainNavigationPromise, footerNaivgationPromise]) + ).flat(); } catch (error) { throw JSON.stringify(error, null, 2); }