MCPcopy
hub / github.com/iamvishnusankar/next-sitemap

github.com/iamvishnusankar/next-sitemap @4.3.4 sqlite

repository ↗ · DeepWiki ↗ · release 4.3.4 ↗
248 symbols 543 edges 137 files 39 documented · 16%
README

BANNER

Build Status npm version PRs Welcome follow on Twitter

Table of contents

Getting started

Installation

yarn add next-sitemap

Create config file

next-sitemap requires a basic config file (next-sitemap.config.js) under your project root

next-sitemap will load environment variables from .env files by default.

/** @type {import('next-sitemap').IConfig} */
module.exports = {
  siteUrl: process.env.SITE_URL || 'https://example.com',
  generateRobotsTxt: true, // (optional)
  // ...other options
}

Building sitemaps

Add next-sitemap as your postbuild script

{
  "build": "next build",
  "postbuild": "next-sitemap"
}

Custom config file

You can also use a custom config file instead of next-sitemap.config.js. Just pass --config <your-config-file>.js to build command (Example: custom-config-file)

{
  "build": "next build",
  "postbuild": "next-sitemap --config awesome.config.js"
}

Building sitemaps with pnpm

When using pnpm you need to create a .npmrc file in the root of your project if you want to use a postbuild step:

//.npmrc
enable-pre-post-scripts=true

Index sitemaps (Optional)

📣 From next-sitemap v2.x onwards, sitemap.xml will be Index Sitemap. It will contain urls of all other generated sitemap endpoints.

Index 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)

Splitting large sitemap into multiple files

Define the sitemapSize property in next-sitemap.config.js to split large sitemap into multiple files.

/** @type {import('next-sitemap').IConfig} */
module.exports = {
  siteUrl: 'https://example.com',
  generateRobotsTxt: true,
  sitemapSize: 7000,
}

Above 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.

Configuration Options

property description type
siteUrl Base url of your website string
output (optional) Next.js output modes. Check documentation. standalone, export
changefreq (optional) Change frequency. Default daily string
priority (optional) Priority. Default 0.7 number
sitemapBaseFileName (optional) The name of the generated sitemap file before the file extension. Default "sitemap" string
alternateRefs (optional) Denote multi-language support by unique URL. Default [] AlternateRef[]
sitemapSize(optional) Split large sitemap into multiple files by specifying sitemap size. Default 5000 number
autoLastmod (optional) Add <lastmod/> property. Default true true
exclude (optional) Array of relative paths (wildcard pattern supported) to exclude from listing on sitemap.xml or sitemap-*.xml. e.g.: ['/page-0', '/page-*', '/private/*'].

Apart from this option next-sitemap also offers a custom transform option which could be used to exclude urls that match specific patterns | string[] | | sourceDir (optional) | next.js build directory. Default .next | string | | outDir (optional) | All the generated files will be exported to this directory. Default public | string | | 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 | | additionalPaths (optional) | Async function that returns a list of additional paths to be added to the generated sitemap list. | async function | | generateIndexSitemap | Generate index sitemaps. Default true | boolean | | generateRobotsTxt (optional) | Generate a robots.txt file and list the generated sitemaps. Default false | boolean

Extension points exported contracts — how you extend this code

IRobotPolicy (Interface)
(no doc)
packages/next-sitemap/src/interface.ts
Item (Interface)
(no doc)
docs/lib/toc.ts
DocsPagerProps (Interface)
(no doc)
docs/app/components/pager.tsx
IRobotsTxt (Interface)
(no doc)
packages/next-sitemap/src/interface.ts
Items (Interface)
(no doc)
docs/lib/toc.ts
CardProps (Interface)
(no doc)
docs/app/components/mdx-card.tsx
IConfig (Interface)
(no doc)
packages/next-sitemap/src/interface.ts
CalloutProps (Interface)
(no doc)
docs/app/components/callout.tsx

Core symbols most depended-on inside this repo

cn
called by 45
docs/lib/utils.ts
isNextInternalUrl
called by 17
packages/next-sitemap/src/utils/url.ts
createUrlSet
called by 14
packages/next-sitemap/src/builders/url-set-builder.ts
escapeHtml
called by 9
packages/next-sitemap/src/builders/sitemap-builder.ts
getPath
called by 8
packages/next-sitemap/src/utils/path.ts
buildSitemapXml
called by 8
packages/next-sitemap/src/builders/sitemap-builder.ts
absoluteUrl
called by 7
packages/next-sitemap/src/builders/url-set-builder.ts
log
called by 6
packages/next-sitemap/src/logger.ts

Shape

Function 150
Method 48
Interface 34
Class 16

Languages

TypeScript100%

Modules by API surface

packages/next-sitemap/src/builders/sitemap-builder.ts15 symbols
packages/next-sitemap/src/builders/exportable-builder.ts13 symbols
packages/next-sitemap/src/interface.ts12 symbols
packages/next-sitemap/src/logger.ts9 symbols
docs/app/components/ui/use-toast.ts9 symbols
packages/next-sitemap/src/parsers/config-parser.ts7 symbols
packages/next-sitemap/src/utils/url.ts6 symbols
packages/next-sitemap/src/utils/matcher.ts6 symbols
packages/next-sitemap/src/builders/url-set-builder.ts6 symbols
docs/lib/toc.ts6 symbols
packages/next-sitemap/src/parsers/manifest-parser.ts5 symbols
packages/next-sitemap/src/builders/robots-txt-builder.ts5 symbols

Dependencies from manifests, versioned

@corex/deepmerge4.0.43 · 1×
@corex/workspace4.0.43 · 1×
@next/env13.5.6 · 1×
@radix-ui/react-dropdown-menu2.0.4 · 1×
@radix-ui/react-toast1.1.4 · 1×
@t3-oss/env-nextjs0.3.1 · 1×
@tailwindcss/typography0.5.9 · 1×
@types/node20.2.3 · 1×
@types/react18.2.33 · 1×
@types/react-dom18.2.14 · 1×
@typescript-eslint/eslint-plugin6.9.1 · 1×
@typescript-eslint/parser6.9.1 · 1×

For agents

$ claude mcp add next-sitemap \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact