When viewing the sitemap built by my site, it generates the sitemap incorrectly. The following code is used to generate the sitemaps.
import { db } from '@/server/db';
import { MetadataRoute } from 'next';
export async function generateSitemaps() {
return [{id: 0}, {id: 1}, {id: 2}];
}
export default async function sitemap({
id: sitemapIndex
}: {
id: number;
}): Promise<MetadataRoute.Sitemap> {
// Google's limit is 50,000 URLs per sitemap
const start = sitemapIndex * 50000;
const end = start + 50000;
const addressSlugs = await db.property.findMany({
where: { addressSlug: { not: null } },
skip: start, // Skip to the starting index
take: end - start, // Take the number of properties from start to end
orderBy: {
id: 'asc'
},
select: { addressSlug: true, updatedAt: true }
});
// The addressSlugs field is verified to have all addressSlug fields a string
return addressSlugs.map(({ addressSlug, updatedAt }) => ({
url: `https://www.mfvalue.com/estimator/${addressSlug}`,
lastModified: updatedAt || new Date()
}));
}
The error can be found here: https://www.mfvalue.com/estimator/sitemap/0.xml