Skip to content

✨ Community Contribution: Next Dynamic Sitemap Generator - Automated SEO Sitemap Generation for Next.js #1110

@parsajiravand

Description

@parsajiravand

πŸš€ Community Contribution: Next Dynamic Sitemap Generator

Hi Next.js team and community! πŸ‘‹

I'm excited to share a community-built tool that enhances SEO capabilities for Next.js applications.

πŸ“¦ Package: next-dynamic-sitemap-generator

NPM: https://www.npmjs.com/package/next-dynamic-sitemap-generator
GitHub: https://github.com/parsajiravand/next-dynamic-sitemap-generator
Version: 1.0.1
License: MIT

🎯 What It Does

Automatically generates sitemap.xml and robots.txt files for Next.js applications with advanced features that complement Next.js's built-in capabilities.

✨ Key Features

  • πŸ” Auto-Detection: Automatically detects routes from both pages/ and app/ directories
  • 🎯 Dynamic Routes: Full support for Next.js dynamic routes ([slug], [...params], etc.)
  • πŸ“„ Multiple Sitemaps: Generate organized multiple sitemaps with index files:
    • pages.xml - Static pages
    • blog.xml - Blog posts
    • products.xml - E-commerce products
    • tags.xml - Tag/category pages
  • πŸ”„ ISR Support: API endpoints for on-demand sitemap regeneration
  • πŸ“Š Async Data: Fetch dynamic paths from APIs, CMS, databases
  • 🎨 TypeScript: Full TypeScript support with type definitions
  • ⚑ CLI Tool: Zero-config CLI integration (next build && next-dynamic-sitemap-generator)
  • πŸ“ Lightweight: <10kb bundle size, zero dependencies

πŸ”§ Perfect Integration with Next.js

// sitemap.config.js
module.exports = {
  siteUrl: 'https://my-nextjs-app.com',
  sitemaps: [
    {
      id: 'pages',
      includeRoutes: ['/', '/about', '/contact']
    },
    {
      id: 'blog', 
      includeRoutes: ['/blog/**'],
      dynamicPaths: async () => {
        // Fetch from your Next.js API routes or external CMS
        const posts = await fetch('/api/posts').then(r => r.json())
        return posts.map(post => `/blog/${post.slug}`)
      }
    }
  ]
}
// package.json
{
  "scripts": {
    "build": "next build && next-dynamic-sitemap-generator"
  }
}

πŸŽͺ Real-World Use Cases

  • E-commerce: Product sitemaps for better indexing
  • Blogs: Article and tag sitemaps
  • Documentation: Organized section sitemaps
  • Large Apps: Multiple sitemaps for better SEO performance
  • Headless CMS: Dynamic content sitemap generation

πŸ“Š SEO Benefits

  • Search Engine Optimization: Proper XML sitemaps for all content
  • Index Coverage: Ensure all pages are discoverable
  • Performance: Multiple sitemaps for large sites (50k+ URLs)
  • Standards Compliant: Follows sitemap protocol specifications
  • Real-time Updates: ISR-compatible for dynamic content

πŸ”„ Next.js Ecosystem Integration

This package works seamlessly with:

  • βœ… Next.js App Router (app/ directory)
  • βœ… Next.js Pages Router (pages/ directory)
  • βœ… Next.js ISR (Incremental Static Regeneration)
  • βœ… Next.js API Routes for dynamic content
  • βœ… Next.js build process integration

πŸ“š Documentation & Examples

  • Comprehensive README: Installation, configuration, examples
  • Multiple Examples: Simple setup, advanced multi-sitemap, production-ready
  • TypeScript Support: Full type definitions included
  • CLI Documentation: Command-line usage and options

🀝 Community Value

This package fills a gap in the Next.js ecosystem by providing:

  • Automated SEO: No manual sitemap maintenance
  • Scale Support: Handles large applications with multiple sitemaps
  • Developer Experience: Simple integration with existing Next.js workflows
  • Performance: Optimized for build-time generation

πŸ’‘ Potential Next.js Integration Ideas

While this is currently a standalone package, future integration possibilities:

  • Built-in sitemap generation in next.config.js
  • Automatic sitemap generation during next build
  • Integration with Next.js Analytics for sitemap insights
  • Vercel deployment integration

πŸ“ˆ Adoption & Feedback

The package has been built with:

  • Test Coverage: Comprehensive unit tests
  • Type Safety: Full TypeScript implementation
  • Documentation: Extensive examples and guides
  • Community Focus: Open source and MIT licensed

Would love to hear feedback from the Next.js team and community! Is this the kind of tooling that would be valuable to include in the broader Next.js ecosystem?


Tags: enhancement, community-contribution, seo, sitemap, tooling, ecosystem


Posted with ❀️ from the Next.js community

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions