From 094456f985a0c086cfc9080b7419feb32dfad37a Mon Sep 17 00:00:00 2001 From: Kirill Kurko Date: Thu, 14 Mar 2024 18:34:00 +0300 Subject: [PATCH] Implement sitemap --- src/app/sitemap.ts | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/app/sitemap.ts diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts new file mode 100644 index 0000000..79624d9 --- /dev/null +++ b/src/app/sitemap.ts @@ -0,0 +1,64 @@ +import { MetadataRoute } from 'next'; +import { BASE_URL } from '../utils/const'; +import { getAllBlogPosts } from '@lib/models/blog'; + +export default function sitemap(): MetadataRoute.Sitemap { + const blogPostsSitemap = getBlogPostsSitemap(); + + return [ + { + url: `${BASE_URL}/`, + lastModified: new Date(), + changeFrequency: 'yearly', + priority: 1, + }, + { + url: `${BASE_URL}/about`, + lastModified: new Date(), + changeFrequency: 'monthly', + priority: 0.9, + }, + { + url: `${BASE_URL}/blog`, + lastModified: new Date(), + changeFrequency: 'weekly', + priority: 0.9, + }, + ...blogPostsSitemap, + { + url: `${BASE_URL}/emoji`, + lastModified: new Date(), + changeFrequency: 'monthly', + priority: 0.8, + }, + { + url: `${BASE_URL}/gallery`, + lastModified: new Date(), + changeFrequency: 'monthly', + priority: 0.8, + }, + { + url: `${BASE_URL}/newsletter`, + lastModified: new Date(), + changeFrequency: 'monthly', + priority: 0.8, + }, + { + url: `${BASE_URL}/snippets`, + lastModified: new Date(), + changeFrequency: 'monthly', + priority: 0.8, + }, + ]; +} + +function getBlogPostsSitemap(): MetadataRoute.Sitemap { + const blogPosts = getAllBlogPosts(); + + return blogPosts.map((blogPost) => ({ + url: `${BASE_URL}/blog/${blogPost.slug}`, + lastModified: new Date(), + changeFrequency: 'monthly', + priority: 0.7, + })); +}