-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathsitemap.ts
More file actions
50 lines (44 loc) · 1.62 KB
/
Copy pathsitemap.ts
File metadata and controls
50 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { MetadataRoute } from "next";
import { getAllPosts, getAllTags, tagToSlug } from "@/lib/blog";
import { SITE } from "@/lib/site";
// Static surface — landing + docs + blog index. Per-post and per-tag entries
// are appended below from the MDX frontmatter / tag list.
const STATIC_ROUTES: Array<{
path: string;
changeFrequency: MetadataRoute.Sitemap[number]["changeFrequency"];
priority: number;
}> = [
{ path: "/", changeFrequency: "weekly", priority: 1.0 },
{ path: "/docs", changeFrequency: "weekly", priority: 0.9 },
{ path: "/playground", changeFrequency: "monthly", priority: 0.8 },
{ path: "/blog", changeFrequency: "weekly", priority: 0.8 },
{ path: "/examples", changeFrequency: "monthly", priority: 0.7 },
];
export default function sitemap(): MetadataRoute.Sitemap {
const now = new Date();
const posts = getAllPosts();
const tags = getAllTags();
const staticEntries = STATIC_ROUTES.map(
({ path, changeFrequency, priority }) => ({
url: `${SITE.url}${path === "/" ? "" : path}`,
lastModified: now,
changeFrequency,
priority,
}),
);
const postEntries: MetadataRoute.Sitemap = posts.map((post) => ({
url: `${SITE.url}/blog/${post.slug}`,
lastModified: new Date(
post.frontmatter.updatedAt ?? post.frontmatter.publishedAt,
),
changeFrequency: "monthly",
priority: 0.7,
}));
const tagEntries: MetadataRoute.Sitemap = tags.map(({ tag }) => ({
url: `${SITE.url}/blog/tags/${tagToSlug(tag)}`,
lastModified: now,
changeFrequency: "monthly",
priority: 0.5,
}));
return [...staticEntries, ...postEntries, ...tagEntries];
}