81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import type { MetadataRoute } from 'next'
|
|
import { client } from '@/shared/lib/sanity'
|
|
import { POST_SLUGS_QUERY, EVENT_SLUGS_QUERY, CATEGORIES_QUERY } from '@/shared/lib/sanity'
|
|
import { siteConfig } from '@/shared/config/site'
|
|
import type { Category } from '@/entities/category'
|
|
|
|
async function fetchSafely<T>(query: string, fallback: T): Promise<T> {
|
|
try {
|
|
return await client.fetch(query)
|
|
} catch {
|
|
return fallback
|
|
}
|
|
}
|
|
|
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|
const baseUrl = siteConfig.url
|
|
|
|
// Static pages
|
|
const staticPages: MetadataRoute.Sitemap = [
|
|
{
|
|
url: baseUrl,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'daily',
|
|
priority: 1,
|
|
},
|
|
{
|
|
url: `${baseUrl}/posts`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'daily',
|
|
priority: 0.9,
|
|
},
|
|
{
|
|
url: `${baseUrl}/events`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'daily',
|
|
priority: 0.8,
|
|
},
|
|
{
|
|
url: `${baseUrl}/about`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'monthly',
|
|
priority: 0.7,
|
|
},
|
|
{
|
|
url: `${baseUrl}/contacts`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'monthly',
|
|
priority: 0.7,
|
|
},
|
|
]
|
|
|
|
// Dynamic pages - posts
|
|
const postSlugs = await fetchSafely<string[]>(POST_SLUGS_QUERY, [])
|
|
const postPages: MetadataRoute.Sitemap = postSlugs.map((slug) => ({
|
|
url: `${baseUrl}/posts/${slug}`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.8,
|
|
}))
|
|
|
|
// Dynamic pages - events
|
|
const eventSlugs = await fetchSafely<string[]>(EVENT_SLUGS_QUERY, [])
|
|
const eventPages: MetadataRoute.Sitemap = eventSlugs.map((slug) => ({
|
|
url: `${baseUrl}/events/${slug}`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.7,
|
|
}))
|
|
|
|
// Dynamic pages - categories
|
|
const categories = await fetchSafely<Category[]>(CATEGORIES_QUERY, [])
|
|
const categoryPages: MetadataRoute.Sitemap = categories.map((category) => ({
|
|
url: `${baseUrl}/categories/${category.slug.current}`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'weekly' as const,
|
|
priority: 0.6,
|
|
}))
|
|
|
|
return [...staticPages, ...postPages, ...eventPages, ...categoryPages]
|
|
}
|