npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

next-advanced-sitemap

v1.4.0

Published

Advanced sitemap generator for Next.js. Powerful support for Google Images, Video, News, and Hreflang (multilingual). Type-safe and built for App Router.

Readme

next-advanced-sitemap

License: FPL Version CI Status

A robust, type-safe XML sitemap, sitemap index, and robots.txt generator for Next.js App Router applications (>= 13.0.0).

It provides native support for Google Images, Google Video, Google News, Hreflang (multilingual), Master Sitemap Indexes (<sitemapindex>), Robots.txt Builder (buildRobotsText), Large-Scale Dataset Chunking, and Cross-Field Semantic Validation.

Full Documentation & API Reference: For complete technical specifications, in-depth extension guides, and validation rules, see DOCUMENTATION.md.


What's New in v1.4.0 (Hardening & Strict Contract Release)

  • <video:family_friendly> is now serialized — the property was previously declared in the type but silently dropped from the XML output (fix #39).
  • Cross-field validation handles booleans — requires_subscription: true now correctly triggers Rule B rejection with price.type: 'own' (fix #40).
  • Strict loc-only sitemap index contract — the undocumented url fallback on SitemapIndexEntry was removed; passing url now throws a clear validation error (breaking change, fix #47).
  • Strict maxAge validation — negative, NaN, Infinity, or non-numeric values now throw a descriptive error instead of silently falling back (fix #49).
  • 50,000-URL guardrail on single sitemaps — generateXml() now enforces the sitemaps.org upper bound, like the existing index guardrail; use chunkSitemapEntries() for larger payloads (fix #50).
  • Shared buildCacheControlHeader() — deduplicated Cache-Control logic across all response generators into one exported utility (fix #45).
  • English-first, modernized codebase — all internal comments/JSDoc migrated to English; tsconfig.json and test imports hardened for NodeNext / strict JSON tooling (fixes #41-#44, #48).

Key Features

  • Native Robots.txt Generator (buildRobotsText) (v1.3.10): Instantly generate standardized, clean robots.txt text content with full support for typed user-agents, allow/disallow paths, crawl-delay directives, inline host rules, sitemap links, and array-based allow / disallow directives. v1.3.10 adds the final RFC compliance sanitization pass — it removes excessive blank lines, trims trailing whitespace, normalizes paths to begin with /, strips Windows carriage returns, and preserves getRobotsTextResponse() text/plain delivery hardening with X-Content-Type-Options: nosniff. The IDE still offers autocomplete for major crawlers like Googlebot, Bingbot, GPTBot, ClaudeBot, and you can still use custom values such as CustomBot/1.0. If host is omitted, the helper auto-detects the root origin from the first sitemap URL to simplify staging, preview, and production setups.
  • Master Sitemap Indexing (getServerSitemapIndexResponse): Seamlessly link multiple child sitemaps to bypass search engine structural limits (50,000 URLs / 50MB per file).
  • Index URL Escaping & Query Parameters Safety (v1.2.8): Rigorous URL sanitization and XML entity escaping (& to &amp;, <, >, ", ') for <sitemapindex> child <loc> URLs, guaranteeing RFC 3986 and XML 1.0 compliance when index locations contain query parameters (?, &, =) or reserved characters.
  • Google Images Extensions: Full support for titles, captions, local SEO positioning (geo_location), and copyright licensing (license).
  • Google Video Extensions: Support for live stream markers (live), SafeSearch (family_friendly, serialized since v1.4.0), monetization models (price), paywall signals (requires_subscription), restrictions (restriction, platform), categories, and tags.
  • Google News Extensions: Support for required metadata, 48-hour freshness rules, and stock market tickers (stock_tickers).
  • Multilingual (Hreflang): Native xhtml:link alternate language/region links.
  • Large-Scale Data Chunking (chunkSitemapEntries): High-performance O(N) utility function to segment large database outputs into compliant sub-arrays.
  • Cross-Field Semantic Validation: Pre-generation validation engine that catches logical data contradictions before XML emission (including boolean requires_subscription since v1.4.0).
  • Payload Guardrails: Fail-fast volume checks — 50,000-URL limit on single sitemaps and 50,000-child limit on index payloads.
  • Edge Cache Optimization: Dynamic header generation for CDN caching with custom TTL support (maxAge), built on a single shared buildCacheControlHeader() utility. Invalid values (negative, NaN, Infinity) throw a clear error since v1.4.0.
  • Automatic Sanitization & Escaping: Deep XML escaping (&, <, >, ", ') and automatic whitespace trimming. escapeXml() is a single-pass encoder over raw input — always pass unescaped text (e.g. &, not &amp;) to avoid double-encoding.

Installation

npm install next-advanced-sitemap
# or
yarn add next-advanced-sitemap
# or
pnpm add next-advanced-sitemap

Quick Start

1. Standard Sitemap Route (app/sitemap-records.xml/route.ts)

import { getServerSitemapResponse, SitemapEntry } from 'next-advanced-sitemap';

export async function GET() {
  const entries: SitemapEntry[] = [
    {
      url: 'https://fomadev.com',
      lastmod: new Date(),
      changefreq: 'daily',
      priority: 1.0,
      alternates: [
        { hreflang: 'en', href: 'https://fomadev.com/en' },
        { hreflang: 'fr', href: 'https://fomadev.com/fr' }
      ]
    },
    {
      url: 'https://fomadev.com/videos/masterclass',
      priority: 0.9,
      videos: [
        {
          thumbnail_loc: 'https://fomadev.com/thumbs/masterclass.jpg',
          title: 'Next.js Advanced Masterclass',
          description: 'Building enterprise grade architectures.',
          duration: 7200,
          view_count: 25000,
          category: 'Technology',
          tags: ['nextjs', 'typescript']
        }
      ]
    }
  ];

  return getServerSitemapResponse(entries, {
    autoLastmod: true,
    sortByPriority: true,
    maxAge: 3600
  });
}

2. Master Sitemap Index Route (app/sitemap.xml/route.ts)

import { getServerSitemapIndexResponse, SitemapIndexEntry } from 'next-advanced-sitemap';

export async function GET() {
  const subSitemaps: SitemapIndexEntry[] = [
    {
      loc: 'https://fomadev.com/sitemap-records.xml',
      lastmod: new Date()
    },
    {
      loc: 'https://fomadev.com/api/sitemap?page=1&category=tech', // Query parameters are safely escaped into &amp;
      lastmod: '2026-08-01T00:00:00.000Z'
    }
  ];

  return getServerSitemapIndexResponse(subSitemaps, {
    autoLastmod: true,
    maxAge: 86400
  });
}

3. Native Robots.txt Route (app/robots.txt/route.ts)

import { getRobotsTextResponse, type KnownUserAgent } from 'next-advanced-sitemap';

const knownBots: KnownUserAgent[] = ['Googlebot', 'GPTBot', 'ClaudeBot', 'CustomBot/1.0'];

export async function GET() {
  return getRobotsTextResponse({
    rules: [
      {
        userAgent: '*',
        allow: '/',
        disallow: ['/admin/', '/private/'],
        crawlDelay: 2
      },
      {
        userAgent: [knownBots[0], knownBots[1]],
        disallow: '/'
      },
      {
        userAgent: knownBots[3],
        allow: '/public/'
      }
    ],
    sitemap: [
      'https://staging.fomadev.com/sitemap.xml',
      'https://staging.fomadev.com/sitemap-news.xml'
    ],
    maxAge: 86400,
    // host is optional: it is automatically inferred from the first sitemap URL
  });
}

In v1.3.10, if host is omitted, the helper automatically extracts the origin from the first sitemap URL and writes Host: https://staging.fomadev.com for you. The final RFC compliance sanitizer also trims trailing spaces, removes Windows carriage returns, collapses excessive blank lines, and normalizes missing leading slashes for Allow / Disallow paths. The getRobotsTextResponse() wrapper keeps enforcing Content-Type: text/plain; charset=utf-8 and X-Content-Type-Options: nosniff, while preserving explicit Crawl-delay directives, Allow sub-route overrides, and multi-sitemap rendering. An explicit host still takes precedence if you need to override the detected value. The KnownUserAgent type also gives IDE autocomplete for the main crawlers while preserving custom string values.

4. Large Dataset Chunking (chunkSitemapEntries)

import { chunkSitemapEntries, SitemapEntry } from 'next-advanced-sitemap';

const massiveDatabaseRows: SitemapEntry[] = [ /* 120,000 database items */ ];

// Slice into compliant batches of 40,000 links
const partitionedSitemaps = chunkSitemapEntries(massiveDatabaseRows, 40000);

Documentation and API Manual

For complete technical specifications, interface definitions, cross-field validation rules, and full version history, please consult the dedicated manual:

DOCUMENTATION.md


License

This project is licensed under the FomaDev Public License (FPL).

  • Free Use: Authorized for personal and commercial projects as a dependency.
  • Contributions: Authorized via Pull Requests to the official repository.
  • Restrictions: Independent forks, source code redistribution, or building competing products based on this engine require a paid commercial license.

Copyright (c) 2026 Fordi / FomaDev.