iamvishnusankar / next-sitemap

Sitemap generator for next.js. Generate sitemap(s) and robots.txt for all static/pre-rendered/dynamic/server-side pages.
https://next-sitemap.iamvishnusankar.com
MIT License
3.17k stars 120 forks source link

not possible to exclude sitemap from "main" sitemap while including it in robots.txt #823

Open Sammeeey opened 3 weeks ago

Sammeeey commented 3 weeks ago

Describe the bug I have this in my sitemap.xml (when using robotsTxtOptions.additionalSitemaps):

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://www.domain.com/sitemap-0.xml</loc>
  </sitemap>
  <sitemap>
    <loc>https://www.domain.com/server-sitemap-index.xml</loc>
  </sitemap>
  <sitemap>
</sitemapindex>

When I want this:

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://www.domain.com/sitemap-0.xml</loc>
  </sitemap>
</sitemapindex>

To Reproduce

  1. create server-sitemap-index.xml/route.ts to generate server-sitemap

  2. next-sitemap.config.js:

    /** @type {import('next-sitemap').IConfig} */
    const siteUrl = process.env.NEXT_PUBLIC_SITE_URL
    module.exports = {
    siteUrl: siteUrl,
    sitemapSize: 50000,
    generateRobotsTxt: true,
    exclude: ['/server-sitemap-index.xml', '/sitemap/*'],
    robotsTxtOptions: {
    additionalSitemaps: [
      `${siteUrl}/server-sitemap-index.xml`,
    ],
    },
    transform: async (config, path) => {
    
    return {
      loc: path,
    }
    }
    }

    But robots.txt should include the server-sitemap-index.xml:

    
    # *
    User-agent: *
    Allow: /

Host

Host: https://www.domain.com

Sitemaps

Sitemap: https://www.domain.com/sitemap.xml Sitemap: https://www.domain.com/server-sitemap-index.xml



**Expected behavior**
 `robotsTxtOptions.additionalSitemaps` shouldn't add the sitemap to `sitemap.xml` BUT only to robots.txt

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.