Need a custom feature? We can help!
Sitemap Configuration
The sitemap configuration in StartupFast.dev allows you to control how search engines index your website's content. This guide explains how to configure your sitemap settings.
Basic Configuration
The sitemap configuration is managed in lib/configuration/seo/sitemapConfig.ts
. Here's a basic example:
1export const sitemapConfig: SitemapConfiguration = { 2 defaultDomain: process.env.NEXT_PUBLIC_APP_URL!, 3 staticRoutes: [ 4 { path: "/", changeFrequency: "monthly" }, 5 { path: "/blog", changeFrequency: "weekly", priority: "0.8" }, 6 ], 7 blogPosts: { 8 include: true, 9 url: "/blog", 10 }, 11 // ... other sections 12};
Configuration Options
Default Domain
Set your application's base URL using the defaultDomain
property. This should match your NEXT_PUBLIC_APP_URL
environment variable:
1defaultDomain: process.env.NEXT_PUBLIC_APP_URL!;
Static Routes
Define static routes that should always be included in your sitemap:
1staticRoutes: [ 2 { 3 path: "/", // URL path 4 changeFrequency: "monthly", // How often the page changes 5 priority: "0.8", // SEO priority (optional, defaults to 0.5) 6 }, 7 // Add more static routes... 8];
Each static route can have:
path
: The URL path (required)changeFrequency
: How often the page changes (optional, defaults to "monthly")priority
: SEO priority from 0.0 to 1.0 (optional, defaults to 0.5)
Dynamic Sections
The sitemap builder supports several dynamic sections that can be toggled on/off:
1blogPosts: { 2 include: true, // Enable/disable blog posts in sitemap 3 url: "/blog" // Base URL for blog posts 4}, 5categories: { 6 include: true, 7 url: "/blog/categories" 8}, 9authors: { 10 include: true, 11 url: "/blog/authors" 12}, 13dashboard: { 14 include: true, 15 url: "/dashboard" 16}
Each section has:
include
: Boolean flag to toggle inclusion in the sitemapurl
: Base URL for that section
How It Works
The sitemap builder (lib/seo/sitemap-builder.ts
) automatically:
-
Includes all configured static routes
-
Adds all blog posts (if enabled) with:
- URL:
/blog/[slug]
- Last modified: Post date
- Change frequency: "monthly"
- Priority: 0.7
- URL:
-
Adds all category pages (if enabled) with:
- URL:
/blog/category/[category]
- Change frequency: "monthly"
- Priority: 0.5
- URL:
-
Adds all author pages (if enabled) with:
- URL:
/blog/author/[author]
- Change frequency: "monthly"
- Priority: 0.5
- URL:
Example Configuration
Here's a complete example showing all available options:
1export const sitemapConfig: SitemapConfiguration = { 2 defaultDomain: process.env.NEXT_PUBLIC_APP_URL!, 3 staticRoutes: [ 4 { path: "/", changeFrequency: "monthly" }, 5 { path: "/blog", changeFrequency: "weekly", priority: "0.8" }, 6 { path: "/about", changeFrequency: "monthly", priority: "0.6" }, 7 { path: "/contact", changeFrequency: "yearly", priority: "0.5" }, 8 ], 9 blogPosts: { 10 include: true, 11 url: "/blog", 12 }, 13 categories: { 14 include: true, 15 url: "/blog/categories", 16 }, 17 authors: { 18 include: true, 19 url: "/blog/authors", 20 }, 21 dashboard: { 22 include: false, // Exclude dashboard from sitemap 23 url: "/dashboard", 24 }, 25};
Best Practices
-
Update Frequencies: Choose appropriate change frequencies:
always
: For pages that change multiple times per dayhourly
: For news sites or frequently updated contentdaily
: For active blogs or dynamic contentweekly
: For regularly updated sectionsmonthly
: For fairly static contentyearly
: For very static contentnever
: For archived content
-
Priorities: Use priorities wisely:
- Homepage: 1.0
- Main sections: 0.8
- Blog posts: 0.7
- Categories/Tags: 0.5
- Less important pages: 0.3-0.4
-
Environment Variables: Always set your
NEXT_PUBLIC_APP_URL
environment variable to ensure correct sitemap generation. -
Dynamic Content: Enable only the dynamic sections that are actually used in your application.