forked from nuotsu/sanitypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitemap.ts
34 lines (32 loc) · 952 Bytes
/
sitemap.ts
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
import { fetchSanity, groq } from '@/lib/sanity'
import { BASE_URL } from '@/lib/processUrl'
import type { MetadataRoute } from 'next'
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const allPages = await fetchSanity<Record<string, MetadataRoute.Sitemap>>(
groq`{
'pages': *[
_type == 'page' &&
!(metadata.slug.current in ['404']) &&
metadata.noIndex != true
]|order(metadata.slug.current){
'url': $baseUrl + select(metadata.slug.current == 'index' => '', metadata.slug.current),
'lastModified': _updatedAt,
'priority': select(
metadata.slug.current == 'index' => 1,
0.5
),
},
'posts': *[_type == 'blog.post' && metadata.noIndex != true]|order(name){
'url': $baseUrl + 'blog/' + metadata.slug.current,
'lastModified': _updatedAt,
'priority': 0.4
}
}`,
{
params: {
baseUrl: BASE_URL + '/',
},
},
)
return Object.values(allPages).flat()
}