{"id":13423779,"url":"https://github.com/iamvishnusankar/next-sitemap","last_synced_at":"2025-05-14T22:04:10.915Z","repository":{"id":36959115,"uuid":"284463513","full_name":"iamvishnusankar/next-sitemap","owner":"iamvishnusankar","description":"Sitemap generator for next.js. Generate sitemap(s) and robots.txt for all static/pre-rendered/dynamic/server-side pages.","archived":false,"fork":false,"pushed_at":"2025-05-05T07:35:58.000Z","size":1090820,"stargazers_count":3528,"open_issues_count":15,"forks_count":134,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-07T21:59:14.053Z","etag":null,"topics":["next-sitemap","nextjs","react","seo","sitemap","sitemap-generator","typescript"],"latest_commit_sha":null,"homepage":"https://next-sitemap.iamvishnusankar.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iamvishnusankar.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["iamvishnusankar"]}},"created_at":"2020-08-02T13:07:45.000Z","updated_at":"2025-05-06T16:29:05.000Z","dependencies_parsed_at":"2024-04-22T08:57:15.666Z","dependency_job_id":"ed96856f-cdfc-47a6-9835-690b66567b80","html_url":"https://github.com/iamvishnusankar/next-sitemap","commit_stats":{"total_commits":604,"total_committers":27,"mean_commits":22.37037037037037,"dds":0.5248344370860927,"last_synced_commit":"0d69597ca5bbfa1db670a711bf5d5a2eb3bd34fe"},"previous_names":[],"tags_count":334,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamvishnusankar%2Fnext-sitemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamvishnusankar%2Fnext-sitemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamvishnusankar%2Fnext-sitemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamvishnusankar%2Fnext-sitemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamvishnusankar","download_url":"https://codeload.github.com/iamvishnusankar/next-sitemap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235686,"owners_count":22036962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["next-sitemap","nextjs","react","seo","sitemap","sitemap-generator","typescript"],"created_at":"2024-07-31T00:00:42.282Z","updated_at":"2025-05-14T22:04:10.880Z","avatar_url":"https://github.com/iamvishnusankar.png","language":"TypeScript","funding_links":["https://github.com/sponsors/iamvishnusankar"],"categories":["Extensions","TypeScript","Nextjs Plugins","🌐 Web Development - Frontend","Tools"],"sub_categories":[],"readme":"[![BANNER](./assets/banner.svg)](https://vercel.com/?utm_source=next-sitemap\u0026utm_campaign=oss)\n\n\u003cdiv align=\"center\"\u003e\n\n[![Build Status](https://dev.azure.com/iamvishnusankar/Public/_apis/build/status/iamvishnusankar.next-sitemap?branchName=master)](https://dev.azure.com/iamvishnusankar/Public/_build/latest?definitionId=126\u0026branchName=master)\n[![npm version](https://badge.fury.io/js/next-sitemap.svg)](https://badge.fury.io/js/next-sitemap)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/iamvishnusankar/next-sitemap/pulls)\n\u003ca href=\"https://twitter.com/intent/follow?screen_name=iamvishnusankar\"\u003e\n\u003cimg src=\"https://img.shields.io/twitter/follow/iamvishnusankar?style=social\u0026logo=twitter\" alt=\"follow on Twitter\"\u003e\n\u003c/a\u003e\n\n\u003c/div\u003e\n\n## Table of contents\n\n- [Getting started](#getting-started)\n  - [Installation](#installation)\n  - [Create config file](#create-config-file)\n  - [Building sitemaps](#building-sitemaps)\n    - [Custom config file](#custom-config-file)\n    - [Building sitemaps with pnpm](#building-sitemaps-with-pnpm)\n- [Index sitemaps](#index-sitemaps-optional)\n- [Splitting large sitemap into multiple files](#splitting-large-sitemap-into-multiple-files)\n- [Configuration Options](#configuration-options)\n- [Custom transformation function](#custom-transformation-function)\n- [Full configuration example](#full-configuration-example)\n- [Generating dynamic/server-side sitemaps](#generating-dynamicserver-side-sitemaps)\n- [Typescript JSDoc](#typescript-jsdoc)\n\n## Getting started\n\n### Installation\n\n```shell\nyarn add next-sitemap\n```\n\n### Create config file\n\n`next-sitemap` requires a basic config file (`next-sitemap.config.js`) under your project root\n\n\u003e ✅ `next-sitemap` will load environment variables from `.env` files by default.\n\n```js\n/** @type {import('next-sitemap').IConfig} */\nmodule.exports = {\n  siteUrl: process.env.SITE_URL || 'https://example.com',\n  generateRobotsTxt: true, // (optional)\n  // ...other options\n}\n```\n\n### Building sitemaps\n\nAdd next-sitemap as your postbuild script\n\n```json\n{\n  \"build\": \"next build\",\n  \"postbuild\": \"next-sitemap\"\n}\n```\n\n#### Custom config file\n\nYou can also use a custom config file instead of `next-sitemap.config.js`. Just pass `--config \u003cyour-config-file\u003e.js` to build command (Example: [custom-config-file](https://github.com/iamvishnusankar/next-sitemap/tree/master/examples/custom-config-file))\n\n```json\n{\n  \"build\": \"next build\",\n  \"postbuild\": \"next-sitemap --config awesome.config.js\"\n}\n```\n\n#### Building sitemaps with pnpm\n\nWhen using pnpm you need to create a `.npmrc` file in the root of your project if you want to use a postbuild step:\n\n```\n//.npmrc\nenable-pre-post-scripts=true\n```\n\n## Index sitemaps (Optional)\n\n📣 From `next-sitemap` v2.x onwards, `sitemap.xml` will be [Index Sitemap](https://developers.google.com/search/docs/advanced/sitemaps/large-sitemaps). It will contain urls of all other generated sitemap endpoints.\n\nIndex sitemap generation can be turned off by setting `generateIndexSitemap: false` in next-sitemap config file. (This is useful for small/hobby sites which does not require an index sitemap) (Example: [no-index-sitemaps](https://github.com/iamvishnusankar/next-sitemap/tree/master/examples/no-index-sitemaps))\n\n## Splitting large sitemap into multiple files\n\nDefine the `sitemapSize` property in `next-sitemap.config.js` to split large sitemap into multiple files.\n\n```js\n/** @type {import('next-sitemap').IConfig} */\nmodule.exports = {\n  siteUrl: 'https://example.com',\n  generateRobotsTxt: true,\n  sitemapSize: 7000,\n}\n```\n\nAbove is the minimal configuration to split a large sitemap. When the number of URLs in a sitemap is more than 7000, `next-sitemap` will create sitemap (e.g. sitemap-0.xml, sitemap-1.xml) and index (e.g. sitemap.xml) files.\n\n## Configuration Options\n\n| property                                            | description                                                                                                                                                                                                                                                                                                                                                                                                                          | type                                                                                                                     |\n| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ |\n| siteUrl                                             | Base url of your website                                                                                                                                                                                                                                                                                                                                                                                                             | string                                                                                                                   |\n| output (optional)                                   | Next.js output modes. [Check documentation](https://nextjs.org/docs/pages/api-reference/next-config-js/output).                                                                                                                                                                                                                                                                                                                      | `standalone`, `export`                                                                                                   |\n| changefreq (optional)                               | Change frequency. Default `daily`                                                                                                                                                                                                                                                                                                                                                                                                    | string                                                                                                                   |\n| priority (optional)                                 | Priority. Default `0.7`                                                                                                                                                                                                                                                                                                                                                                                                              | number                                                                                                                   |\n| sitemapBaseFileName (optional)                      | The name of the generated sitemap file before the file extension. Default `\"sitemap\"`                                                                                                                                                                                                                                                                                                                                                | string                                                                                                                   |\n| alternateRefs (optional)                            | Denote multi-language support by unique URL. Default `[]`                                                                                                                                                                                                                                                                                                                                                                            | AlternateRef[]                                                                                                           |\n| sitemapSize(optional)                               | Split large sitemap into multiple files by specifying sitemap size. Default `5000`                                                                                                                                                                                                                                                                                                                                                   | number                                                                                                                   |\n| autoLastmod (optional)                              | Add `\u003clastmod/\u003e` property. Default `true`                                                                                                                                                                                                                                                                                                                                                                                            | true                                                                                                                     |\n| exclude (optional)                                  | Array of **relative** paths ([wildcard pattern supported](https://www.npmjs.com/package/matcher#usage)) to exclude from listing on `sitemap.xml` or `sitemap-*.xml`. e.g.: `['/page-0', '/page-*', '/private/*']`. \u003cbr\u003e\u003c/br\u003eApart from this option `next-sitemap` also offers a custom `transform` option which could be used to exclude urls that match specific patterns                                                           | string[]                                                                                                                 |\n| sourceDir (optional)                                | next.js build directory. Default `.next`                                                                                                                                                                                                                                                                                                                                                                                             | string                                                                                                                   |\n| outDir (optional)                                   | All the generated files will be exported to this directory. Default `public`                                                                                                                                                                                                                                                                                                                                                         | string                                                                                                                   |\n| transform (optional)                                | A transformation function, which runs **for each** `relative-path` in the sitemap. Returning `null` value from the transformation function will result in the exclusion of that specific `path` from the generated sitemap list.                                                                                                                                                                                                     | async function                                                                                                           |\n| additionalPaths (optional)                          | Async function that returns a list of additional paths to be added to the generated sitemap list.                                                                                                                                                                                                                                                                                                                                    | async function                                                                                                           |\n| generateIndexSitemap                                | Generate index sitemaps. Default `true`                                                                                                                                                                                                                                                                                                                                                                                              | boolean                                                                                                                  |\n| generateRobotsTxt (optional)                        | Generate a `robots.txt` file and list the generated sitemaps. Default `false`                                                                                                                                                                                                                                                                                                                                                        | boolean                                                                                                                  |\n| robotsTxtOptions.transformRobotsTxt (optional)      | Custom robots.txt transformer function. (Example: [custom-robots-txt-transformer](https://github.com/iamvishnusankar/next-sitemap/tree/master/examples/custom-robots-txt-transformer)) \u003cbr/\u003e\u003cbr/\u003e Default: `async(config, robotsTxt)=\u003e robotsTxt`                                                                                                                                                                                    | async function                                                                                                           |\n| robotsTxtOptions.policies (optional)                | Policies for generating `robots.txt`.\u003cbr/\u003e\u003cbr/\u003e Default: \u003cbr/\u003e`[{ userAgent: '*', allow: '/' }]`                                                                                                                                                                                                                                                                                                                                     | [IRobotPolicy[]](https://github.com/iamvishnusankar/next-sitemap/blob/master/packages/next-sitemap/src/interface.ts#L14) |\n| robotsTxtOptions.additionalSitemaps (optional)      | Options to add additional sitemaps to `robots.txt` host entry                                                                                                                                                                                                                                                                                                                                                                        | string[]                                                                                                                 |\n| robotsTxtOptions.includeNonIndexSitemaps (optional) | From v2.4x onwards, generated `robots.txt` will only contain url of `index sitemap` and custom provided endpoints from `robotsTxtOptions.additionalSitemaps`. \u003cbr/\u003e \u003cbr/\u003e This is to prevent duplicate url submission (once through index-sitemap -\u003e sitemap-url and once through robots.txt -\u003e HOST) \u003cbr/\u003e\u003cbr/\u003eSet this option `true` to add all generated sitemap endpoints to `robots.txt`\u003cbr\u003e\u003cbr/\u003e Default `false` (Recommended) | boolean                                                                                                                  |\n\n## Custom transformation function\n\nCustom transformation provides an extension method to add, remove or exclude `path` or `properties` from a url-set. Transform function runs **for each** `relative path` in the sitemap. And use the `key`: `value` object to add properties in the XML.\n\nReturning `null` value from the transformation function will result in the exclusion of that specific `relative-path` from the generated sitemap list.\n\n```jsx\n/** @type {import('next-sitemap').IConfig} */\nmodule.exports = {\n  transform: async (config, path) =\u003e {\n    // custom function to ignore the path\n    if (customIgnoreFunction(path)) {\n      return null\n    }\n\n    // only create changefreq along with path\n    // returning partial properties will result in generation of XML field with only returned values.\n    if (customLimitedField(path)) {\n      // This returns `path` \u0026 `changefreq`. Hence it will result in the generation of XML field with `path` and  `changefreq` properties only.\n      return {\n        loc: path, // =\u003e this will be exported as http(s)://\u003cconfig.siteUrl\u003e/\u003cpath\u003e\n        changefreq: 'weekly',\n      }\n    }\n\n    // Use default transformation for all other cases\n    return {\n      loc: path, // =\u003e this will be exported as http(s)://\u003cconfig.siteUrl\u003e/\u003cpath\u003e\n      changefreq: config.changefreq,\n      priority: config.priority,\n      lastmod: config.autoLastmod ? new Date().toISOString() : undefined,\n      alternateRefs: config.alternateRefs ?? [],\n    }\n  },\n}\n```\n\n## Additional paths function\n\n`additionalPaths` this function can be useful if you have a large list of pages, but you don't want to render them all and use [fallback: true](https://nextjs.org/docs/basic-features/data-fetching#fallback-true). Result of executing this function will be added to the general list of paths and processed with `sitemapSize`. You are free to add dynamic paths, but unlike `additionalSitemap`, you do not need to split the list of paths into different files in case there are a lot of paths for one file.\n\nIf your function returns a path that already exists, then it will simply be updated, duplication will not happen.\n\n```js\n/** @type {import('next-sitemap').IConfig} */\nmodule.exports = {\n  additionalPaths: async (config) =\u003e {\n    const result = []\n\n    // required value only\n    result.push({ loc: '/additional-page-1' })\n\n    // all possible values\n    result.push({\n      loc: '/additional-page-2',\n      changefreq: 'yearly',\n      priority: 0.7,\n      lastmod: new Date().toISOString(),\n\n      // acts only on '/additional-page-2'\n      alternateRefs: [\n        {\n          href: 'https://es.example.com',\n          hreflang: 'es',\n        },\n        {\n          href: 'https://fr.example.com',\n          hreflang: 'fr',\n        },\n      ],\n    })\n\n    // using transformation from the current configuration\n    result.push(await config.transform(config, '/additional-page-3'))\n\n    return result\n  },\n}\n```\n\n## Google News, image and video sitemap\n\nUrl set can contain additional sitemaps defined by google. These are\n[Google News sitemap](https://developers.google.com/search/docs/advanced/sitemaps/news-sitemap),\n[image sitemap](https://developers.google.com/search/docs/advanced/sitemaps/image-sitemaps) or\n[video sitemap](https://developers.google.com/search/docs/advanced/sitemaps/video-sitemaps).\nYou can add the values for these sitemaps by updating entry in `transform` function or adding it with\n`additionalPaths`. You have to return a sitemap entry in both cases, so it's the best place for updating\nthe output. This example will add an image and news tag to each entry but IRL you would of course use it with\nsome condition or within `additionalPaths` result.\n\n```js\n/** @type {import('next-sitemap').IConfig} */\nconst config = {\n  transform: async (config, path) =\u003e {\n    return {\n      loc: path, // =\u003e this will be exported as http(s)://\u003cconfig.siteUrl\u003e/\u003cpath\u003e\n      changefreq: config.changefreq,\n      priority: config.priority,\n      lastmod: config.autoLastmod ? new Date().toISOString() : undefined,\n      images: [{ loc: 'https://example.com/image.jpg' }],\n      news: {\n        title: 'Article 1',\n        publicationName: 'Google Scholar',\n        publicationLanguage: 'en',\n        date: new Date(),\n      },\n    }\n  },\n}\n\nexport default config\n```\n\n## Full configuration example\n\nHere's an example `next-sitemap.config.js` configuration with all options\n\n```js\n/** @type {import('next-sitemap').IConfig} */\n\nmodule.exports = {\n  siteUrl: 'https://example.com',\n  changefreq: 'daily',\n  priority: 0.7,\n  sitemapSize: 5000,\n  generateRobotsTxt: true,\n  exclude: ['/protected-page', '/awesome/secret-page'],\n  alternateRefs: [\n    {\n      href: 'https://es.example.com',\n      hreflang: 'es',\n    },\n    {\n      href: 'https://fr.example.com',\n      hreflang: 'fr',\n    },\n  ],\n  // Default transformation function\n  transform: async (config, path) =\u003e {\n    return {\n      loc: path, // =\u003e this will be exported as http(s)://\u003cconfig.siteUrl\u003e/\u003cpath\u003e\n      changefreq: config.changefreq,\n      priority: config.priority,\n      lastmod: config.autoLastmod ? new Date().toISOString() : undefined,\n      alternateRefs: config.alternateRefs ?? [],\n    }\n  },\n  additionalPaths: async (config) =\u003e [\n    await config.transform(config, '/additional-page'),\n  ],\n  robotsTxtOptions: {\n    policies: [\n      {\n        userAgent: '*',\n        allow: '/',\n      },\n      {\n        userAgent: 'test-bot',\n        allow: ['/path', '/path-2'],\n      },\n      {\n        userAgent: 'black-listed-bot',\n        disallow: ['/sub-path-1', '/path-2'],\n      },\n    ],\n    additionalSitemaps: [\n      'https://example.com/my-custom-sitemap-1.xml',\n      'https://example.com/my-custom-sitemap-2.xml',\n      'https://example.com/my-custom-sitemap-3.xml',\n    ],\n  },\n}\n```\n\nAbove configuration will generate sitemaps based on your project and a `robots.txt` like this.\n\n```txt\n# *\nUser-agent: *\nAllow: /\n\n# test-bot\nUser-agent: test-bot\nAllow: /path\nAllow: /path-2\n\n# black-listed-bot\nUser-agent: black-listed-bot\nDisallow: /sub-path-1\nDisallow: /path-2\n\n# Host\nHost: https://example.com\n\n# Sitemaps\nSitemap: https://example.com/sitemap.xml # Index sitemap\nSitemap: https://example.com/my-custom-sitemap-1.xml\nSitemap: https://example.com/my-custom-sitemap-2.xml\nSitemap: https://example.com/my-custom-sitemap-3.xml\n```\n\n## Generating dynamic/server-side sitemaps\n\n`next-sitemap` now provides two APIs to generate server side sitemaps. This will help to dynamically generate `index-sitemap`(s) and `sitemap`(s) by sourcing data from CMS or custom source.\n\n- `getServerSideSitemapIndex`: Generates index sitemaps based on urls provided and returns `application/xml` response. Supports next13+ route.{ts,js} file.\n\n  - To continue using inside pages directory, import `getServerSideSitemapIndexLegacy` instead.\n\n- `getServerSideSitemap`: Generates sitemap based on field entires and returns `application/xml` response. Supports next13+ route.{ts,js} file.\n  - To continue using inside pages directory, import `getServerSideSitemapLegacy` instead.\n\n### Server side index-sitemaps (getServerSideSitemapIndex)\n\nHere's a sample script to generate index-sitemap on server side.\n\n\u003cdetails\u003e\n\u003csummary\u003e1. Index sitemap (app directory)\u003c/summary\u003e\n\nCreate `app/server-sitemap-index.xml/route.ts` file.\n\n```ts\n// app/server-sitemap-index.xml/route.ts\nimport { getServerSideSitemapIndex } from 'next-sitemap'\n\nexport async function GET(request: Request) {\n  // Method to source urls from cms\n  // const urls = await fetch('https//example.com/api')\n\n  return getServerSideSitemapIndex([\n    'https://example.com/path-1.xml',\n    'https://example.com/path-2.xml',\n  ])\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e2. Index sitemap (pages directory) (legacy)\u003c/summary\u003e\n\nCreate `pages/server-sitemap-index.xml/index.tsx` file.\n\n```ts\n// pages/server-sitemap-index.xml/index.tsx\nimport { getServerSideSitemapIndexLegacy } from 'next-sitemap'\nimport { GetServerSideProps } from 'next'\n\nexport const getServerSideProps: GetServerSideProps = async (ctx) =\u003e {\n  // Method to source urls from cms\n  // const urls = await fetch('https//example.com/api')\n\n  return getServerSideSitemapIndexLegacy(ctx, [\n    'https://example.com/path-1.xml',\n    'https://example.com/path-2.xml',\n  ])\n}\n\n// Default export to prevent next.js errors\nexport default function SitemapIndex() {}\n```\n\n\u003c/details\u003e\n\n#### Exclude server index sitemap from robots.txt\n\nNow, `next.js` is serving the dynamic index-sitemap from `http://localhost:3000/server-sitemap-index.xml`.\n\nList the dynamic sitemap page in `robotsTxtOptions.additionalSitemaps` and exclude this path from static sitemap list.\n\n```js\n// next-sitemap.config.js\n\n/** @type {import('next-sitemap').IConfig} */\nmodule.exports = {\n  siteUrl: 'https://example.com',\n  generateRobotsTxt: true,\n  exclude: ['/server-sitemap-index.xml'], // \u003c= exclude here\n  robotsTxtOptions: {\n    additionalSitemaps: [\n      'https://example.com/server-sitemap-index.xml', // \u003c==== Add here\n    ],\n  },\n}\n```\n\nIn this way, `next-sitemap` will manage the sitemaps for all your static pages and your dynamic `index-sitemap` will be listed on robots.txt.\n\n---\n\n### server side sitemap (getServerSideSitemap)\n\nHere's a sample script to generate sitemaps on server side.\n\n\u003cdetails\u003e\n\u003csummary\u003e1. Sitemaps (app directory)\u003c/summary\u003e\n\nCreate `app/server-sitemap.xml/route.ts` file.\n\n```ts\n// app/server-sitemap.xml/route.ts\nimport { getServerSideSitemap } from 'next-sitemap'\n\nexport async function GET(request: Request) {\n  // Method to source urls from cms\n  // const urls = await fetch('https//example.com/api')\n\n  return getServerSideSitemap([\n    {\n      loc: 'https://example.com',\n      lastmod: new Date().toISOString(),\n      // changefreq\n      // priority\n    },\n    {\n      loc: 'https://example.com/dynamic-path-2',\n      lastmod: new Date().toISOString(),\n      // changefreq\n      // priority\n    },\n  ])\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e2. Sitemaps (pages directory) (legacy)\u003c/summary\u003e\n\nCreate `pages/server-sitemap.xml/index.tsx` file.\n\n```ts\n// pages/server-sitemap.xml/index.tsx\nimport { getServerSideSitemapLegacy } from 'next-sitemap'\nimport { GetServerSideProps } from 'next'\n\nexport const getServerSideProps: GetServerSideProps = async (ctx) =\u003e {\n  // Method to source urls from cms\n  // const urls = await fetch('https//example.com/api')\n\n  const fields = [\n    {\n      loc: 'https://example.com', // Absolute url\n      lastmod: new Date().toISOString(),\n      // changefreq\n      // priority\n    },\n    {\n      loc: 'https://example.com/dynamic-path-2', // Absolute url\n      lastmod: new Date().toISOString(),\n      // changefreq\n      // priority\n    },\n  ]\n\n  return getServerSideSitemapLegacy(ctx, fields)\n}\n\n// Default export to prevent next.js errors\nexport default function Sitemap() {}\n```\n\n\u003c/details\u003e\n\nNow, `next.js` is serving the dynamic sitemap from `http://localhost:3000/server-sitemap.xml`.\n\nList the dynamic sitemap page in `robotsTxtOptions.additionalSitemaps` and exclude this path from static sitemap list.\n\n```js\n// next-sitemap.config.js\n\n/** @type {import('next-sitemap').IConfig} */\nmodule.exports = {\n  siteUrl: 'https://example.com',\n  generateRobotsTxt: true,\n  exclude: ['/server-sitemap.xml'], // \u003c= exclude here\n  robotsTxtOptions: {\n    additionalSitemaps: [\n      'https://example.com/server-sitemap.xml', // \u003c==== Add here\n    ],\n  },\n}\n```\n\nIn this way, `next-sitemap` will manage the sitemaps for all your static pages and your dynamic sitemap will be listed on robots.txt.\n\n## Typescript JSDoc\n\nAdd the following line of code in your `next-sitemap.config.js` for nice typescript autocomplete! 💖\n\n```js\n/** @type {import('next-sitemap').IConfig} */\nmodule.exports = {\n  // YOUR CONFIG\n}\n```\n\n![TS_JSDOC](./assets/ts-jsdoc.png)\n\n## Contribution\n\nAll PRs are welcome :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamvishnusankar%2Fnext-sitemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamvishnusankar%2Fnext-sitemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamvishnusankar%2Fnext-sitemap/lists"}