-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
π 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/
andapp/
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 pagesblog.xml
- Blog postsproducts.xml
- E-commerce productstags.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