#How to create sitemap for dynamic routes?

1 messages · Page 1 of 1 (latest)

azure coral
#

I have some routes like [user]/[xyz] that can have potentially large amounts of pages. How does one create a sitemap for this and stay within Google's 50MB limit?

cunning tuskBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

red hamlet
# azure coral I have some routes like `[user]/[xyz]` that can have potentially large amounts o...

you can generate sitemaps like this (read more):

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
}): Promise<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,
  }))
}

Like that you stay within google limits and be able to place everything correctly in the sitemaps

Learn how to use the generateSiteMaps function to create multiple sitemaps for your application.

azure coral
red hamlet
azure coral
red hamlet
azure coral
red hamlet
red hamlet
#

@azure coral solved?

azure coral
#

Is there somewhere I need to mark as solved or accept an answer?

#

At the moment I don't think I'll fill up even a single sitemap but I'm thinking or worst case scenarios and trying to write code that I don't need to touch again

cunning tuskBOT
red hamlet
radiant crown
#

Hello

azure coral
#

@red hamlet how does one create sitemaps for routes like /[user]/[project]? The Next.js example has product before a slug, whereas in my case I have /slug/slug

red hamlet
#

I saw you discussed about that in #off-topic . However, I didnt read through the messages there. You may be able to tell me a conclusion about the messages there?

azure coral
#

It just seems like too much magic involved, making it difficult for a first timer to implement. But I'll give this function another try.

azure coral