generateSitemaps
Uygulamanız için birden fazla site haritası oluşturmak için generateSitemaps işlevini kullanabilirsiniz.
Returns
generateSitemaps, id özelliğine sahip bir nesne dizisi döndürür.
URLs
Üretimde, oluşturulan site haritalarınız /.../sitemap/[id].xml adresinde mevcut olacaktır. Örneğin, /product/sitemap/1.xml.
Geliştirme aşamasında, oluşturulan site haritasını /.../sitemap.xml/[id] adresinde görüntüleyebilirsiniz. Örneğin, /product/sitemap.xml/1. Bu farklılık geçicidir ve üretim formatını takip edecektir.
Example
Örneğin, generateSitemaps kullanarak bir site haritasını bölmek için, id site haritası ile bir dizi nesne döndürün. Ardından, benzersiz site haritalarını oluşturmak için id adresini kullanın.
app/product/sitemap.ts
import { BASE_URL } from '@/app/lib/constants'
export async function generateSitemaps() {
// Fetch the total number of products and calculate the number of sitemaps needed
return [{ id: 0 }, { id: 1 }, { id: 2 }, { id: 3 }]
}
export default async function sitemap({
id,
}: {
id: number
}): MetadataRoute.Sitemap {
// Google's limit is 50,000 URLs per sitemap
const start = id * 50000
const end = start + 50000
const products = await getProducts(
`SELECT id, date FROM products WHERE id BETWEEN ${start} AND ${end}`
)
return products.map((product) => ({
url: `${BASE_URL}/product/${product.id}`
lastModified: product.date,
}))
}