tailwind-nextjs-blog/app/sitemap.ts

19 lines
578 B
TypeScript
Raw Permalink Normal View History

2023-08-16 23:55:57 +08:00
import { MetadataRoute } from 'next';
import { allBlogs } from 'contentlayer/generated';
import siteMetadata from '@/data/siteMetadata';
export default function sitemap(): MetadataRoute.Sitemap {
2023-08-16 23:55:57 +08:00
const siteUrl = siteMetadata.siteUrl;
const blogRoutes = allBlogs.map((post) => ({
url: `${siteUrl}/${post.path}`,
lastModified: post.lastmod || post.date,
2023-08-16 23:55:57 +08:00
}));
const routes = ['', 'blog', 'projects', 'tags'].map((route) => ({
url: `${siteUrl}/${route}`,
lastModified: new Date().toISOString().split('T')[0],
2023-08-16 23:55:57 +08:00
}));
2023-08-16 23:55:57 +08:00
return [...routes, ...blogRoutes];
}