-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsitemap.ts
More file actions
46 lines (39 loc) · 1.07 KB
/
sitemap.ts
File metadata and controls
46 lines (39 loc) · 1.07 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
import type { MetadataRoute } from "next";
import { sitemapQuery } from "@/sanity/lib/queries";
import { sanityFetch } from "@/sanity/lib/live";
import type { SitemapQueryResult } from "@/sanity/types";
import { ContentType } from "@/lib/types";
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const productionDomain = process.env.VERCEL_PROJECT_PRODUCTION_URL;
const site = productionDomain
? `https://${productionDomain}`
: "https://codingcat.dev";
const content = (
await sanityFetch({
query: sitemapQuery,
})
).data as SitemapQueryResult;
const sitemap: MetadataRoute.Sitemap = [
{
url: `${site}`,
lastModified: new Date(),
changeFrequency: "monthly",
priority: 1,
},
{
url: `${site}/search`,
lastModified: new Date(),
changeFrequency: "daily",
priority: 0.1,
},
];
for (const c of content) {
sitemap.push({
url: `${site}${c._type === ContentType.page ? `/${c.slug}` : `/${c._type}/${c.slug}`}`,
lastModified: new Date(),
changeFrequency: "monthly",
priority: 0.5,
});
}
return sitemap;
}