2023-08-16 23:55:57 +08:00
|
|
|
import { MetadataRoute } from 'next';
|
|
|
|
import { allBlogs } from 'contentlayer/generated';
|
|
|
|
import siteMetadata from '@/data/siteMetadata';
|
2023-08-16 23:29:22 +08:00
|
|
|
|
|
|
|
export default function sitemap(): MetadataRoute.Sitemap {
|
2023-08-16 23:55:57 +08:00
|
|
|
const siteUrl = siteMetadata.siteUrl;
|
2023-08-16 23:29:22 +08:00
|
|
|
const blogRoutes = allBlogs.map((post) => ({
|
|
|
|
url: `${siteUrl}/${post.path}`,
|
|
|
|
lastModified: post.lastmod || post.date,
|
2023-08-16 23:55:57 +08:00
|
|
|
}));
|
2023-08-16 23:29:22 +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:29:22 +08:00
|
|
|
|
2023-08-16 23:55:57 +08:00
|
|
|
return [...routes, ...blogRoutes];
|
2023-08-16 23:29:22 +08:00
|
|
|
}
|