From d10037a822738c90c468ae5e616900cee1477f16 Mon Sep 17 00:00:00 2001 From: Uwinfly <165354975+Uwinfly@users.noreply.github.com> Date: Wed, 3 Apr 2024 03:06:05 +0700 Subject: [PATCH] Update sitemap.ts --- app/sitemap.ts | 51 -------------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/app/sitemap.ts b/app/sitemap.ts index fe8ed96ac2..8b13789179 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -1,52 +1 @@ -import { getCollections, getPages, getProducts } from 'lib/shopify'; -import { validateEnvironmentVariables } from 'lib/utils'; -import { MetadataRoute } from 'next'; -type Route = { - url: string; - lastModified: string; -}; - -const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL - ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` - : 'http://localhost:3000'; - -export default async function sitemap(): Promise { - validateEnvironmentVariables(); - - const routesMap = [''].map((route) => ({ - url: `${baseUrl}${route}`, - lastModified: new Date().toISOString() - })); - - const collectionsPromise = getCollections().then((collections) => - collections.map((collection) => ({ - url: `${baseUrl}${collection.path}`, - lastModified: collection.updatedAt - })) - ); - - const productsPromise = getProducts({}).then((products) => - products.map((product) => ({ - url: `${baseUrl}/product/${product.handle}`, - lastModified: product.updatedAt - })) - ); - - const pagesPromise = getPages().then((pages) => - pages.map((page) => ({ - url: `${baseUrl}/${page.handle}`, - lastModified: page.updatedAt - })) - ); - - let fetchedRoutes: Route[] = []; - - try { - fetchedRoutes = (await Promise.all([collectionsPromise, productsPromise, pagesPromise])).flat(); - } catch (error) { - throw JSON.stringify(error, null, 2); - } - - return [...routesMap, ...fetchedRoutes]; -}