|
| 1 | +import type { MetadataRoute } from "next" |
| 2 | +import { SEO } from "@/lib/seo" |
| 3 | +import { getAllBlogPosts } from "@/lib/blog" |
| 4 | + |
| 5 | +/** |
| 6 | + * Generate sitemap for the website |
| 7 | + * Includes all static pages and dynamically generated blog post URLs |
| 8 | + * |
| 9 | + * @see https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap |
| 10 | + */ |
| 11 | +export default function sitemap(): MetadataRoute.Sitemap { |
| 12 | + const baseUrl = SEO.url |
| 13 | + |
| 14 | + // Static pages with their last modified dates and priorities |
| 15 | + const staticPages: MetadataRoute.Sitemap = [ |
| 16 | + { |
| 17 | + url: baseUrl, |
| 18 | + lastModified: new Date(), |
| 19 | + changeFrequency: "daily", |
| 20 | + priority: 1, |
| 21 | + }, |
| 22 | + { |
| 23 | + url: `${baseUrl}/pricing`, |
| 24 | + lastModified: new Date(), |
| 25 | + changeFrequency: "weekly", |
| 26 | + priority: 0.9, |
| 27 | + }, |
| 28 | + { |
| 29 | + url: `${baseUrl}/extension`, |
| 30 | + lastModified: new Date(), |
| 31 | + changeFrequency: "weekly", |
| 32 | + priority: 0.8, |
| 33 | + }, |
| 34 | + { |
| 35 | + url: `${baseUrl}/cloud`, |
| 36 | + lastModified: new Date(), |
| 37 | + changeFrequency: "weekly", |
| 38 | + priority: 0.8, |
| 39 | + }, |
| 40 | + { |
| 41 | + url: `${baseUrl}/slack`, |
| 42 | + lastModified: new Date(), |
| 43 | + changeFrequency: "weekly", |
| 44 | + priority: 0.7, |
| 45 | + }, |
| 46 | + { |
| 47 | + url: `${baseUrl}/provider`, |
| 48 | + lastModified: new Date(), |
| 49 | + changeFrequency: "weekly", |
| 50 | + priority: 0.7, |
| 51 | + }, |
| 52 | + { |
| 53 | + url: `${baseUrl}/enterprise`, |
| 54 | + lastModified: new Date(), |
| 55 | + changeFrequency: "monthly", |
| 56 | + priority: 0.7, |
| 57 | + }, |
| 58 | + { |
| 59 | + url: `${baseUrl}/evals`, |
| 60 | + lastModified: new Date(), |
| 61 | + changeFrequency: "weekly", |
| 62 | + priority: 0.6, |
| 63 | + }, |
| 64 | + { |
| 65 | + url: `${baseUrl}/reviewer`, |
| 66 | + lastModified: new Date(), |
| 67 | + changeFrequency: "weekly", |
| 68 | + priority: 0.6, |
| 69 | + }, |
| 70 | + { |
| 71 | + url: `${baseUrl}/pr-fixer`, |
| 72 | + lastModified: new Date(), |
| 73 | + changeFrequency: "weekly", |
| 74 | + priority: 0.6, |
| 75 | + }, |
| 76 | + // Blog index page |
| 77 | + { |
| 78 | + url: `${baseUrl}/blog`, |
| 79 | + lastModified: new Date(), |
| 80 | + changeFrequency: "daily", |
| 81 | + priority: 0.8, |
| 82 | + }, |
| 83 | + // Legal pages |
| 84 | + { |
| 85 | + url: `${baseUrl}/terms`, |
| 86 | + lastModified: new Date(), |
| 87 | + changeFrequency: "monthly", |
| 88 | + priority: 0.3, |
| 89 | + }, |
| 90 | + { |
| 91 | + url: `${baseUrl}/privacy`, |
| 92 | + lastModified: new Date(), |
| 93 | + changeFrequency: "monthly", |
| 94 | + priority: 0.3, |
| 95 | + }, |
| 96 | + { |
| 97 | + url: `${baseUrl}/legal/cookies`, |
| 98 | + lastModified: new Date(), |
| 99 | + changeFrequency: "monthly", |
| 100 | + priority: 0.2, |
| 101 | + }, |
| 102 | + { |
| 103 | + url: `${baseUrl}/legal/subprocessors`, |
| 104 | + lastModified: new Date(), |
| 105 | + changeFrequency: "monthly", |
| 106 | + priority: 0.2, |
| 107 | + }, |
| 108 | + ] |
| 109 | + |
| 110 | + // Get all published blog posts and generate URLs |
| 111 | + const blogPosts = getAllBlogPosts() |
| 112 | + const blogPages: MetadataRoute.Sitemap = blogPosts.map((post) => ({ |
| 113 | + url: `${baseUrl}/blog/${post.slug}`, |
| 114 | + lastModified: new Date(post.publish_date), |
| 115 | + changeFrequency: "monthly" as const, |
| 116 | + priority: 0.7, |
| 117 | + })) |
| 118 | + |
| 119 | + return [...staticPages, ...blogPages] |
| 120 | +} |
0 commit comments