Capital/app/sitemap.ts

32 lines
774 B
TypeScript
Raw Normal View History

2024-02-24 10:54:47 +00:00
import { MetadataRoute } from "next";
import { SITE_URL } from "@/app/consts";
2024-02-24 14:12:01 +00:00
import { client } from "@/sanity/lib/client";
2024-02-24 10:54:47 +00:00
2024-02-24 14:12:01 +00:00
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const posts = await client.fetch<any[]>(`*[_type == "post"] {
slug, publishedAt,
}`);
2024-02-24 10:54:47 +00:00
return [
{
url: `${SITE_URL}/`,
lastModified: new Date(),
changeFrequency: "weekly",
2024-02-24 13:56:35 +00:00
priority: 1,
2024-02-24 10:54:47 +00:00
},
{
url: `${SITE_URL}/posts`,
lastModified: new Date(),
changeFrequency: "daily",
2024-02-24 13:56:35 +00:00
priority: 0.8,
2024-02-24 10:54:47 +00:00
},
2024-02-24 14:12:01 +00:00
...posts.map((item: any) => ({
url: `${SITE_URL}/posts/${item.slug.current}`,
lastModified: new Date(item.publishedAt),
2024-02-24 10:54:47 +00:00
changeFrequency: "daily" as any,
2024-02-24 13:56:35 +00:00
priority: 0.75,
})),
2024-02-24 10:54:47 +00:00
];
2024-02-24 13:56:35 +00:00
}