mirror of
https://github.com/vercel/commerce.git
synced 2025-05-16 14:36:59 +00:00
28 lines
898 B
TypeScript
28 lines
898 B
TypeScript
import { getCategories, getProducts } from 'lib/medusa';
|
|
import { MetadataRoute } from 'next';
|
|
|
|
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL
|
|
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
|
|
: 'http://localhost:3000';
|
|
|
|
export default async function sitemap(): Promise<Promise<Promise<MetadataRoute.Sitemap>>> {
|
|
const routesMap = ['', '/search'].map((route) => ({
|
|
url: `${baseUrl}${route}`,
|
|
lastModified: new Date().toISOString()
|
|
}));
|
|
|
|
const collections = await getCategories();
|
|
const collectionsMap = collections.map((collection) => ({
|
|
url: `${baseUrl}${collection.path}`,
|
|
lastModified: collection.updatedAt
|
|
}));
|
|
|
|
const products = await getProducts({});
|
|
const productsMap = products.map((product) => ({
|
|
url: `${baseUrl}/product/${product.handle}`,
|
|
lastModified: product.updatedAt
|
|
}));
|
|
|
|
return [...routesMap, ...collectionsMap, ...productsMap];
|
|
}
|