|
1 | 1 | import { env } from '@codebuff/common/env' |
| 2 | +import { getCachedAgents } from '@/server/agents-data' |
2 | 3 |
|
3 | 4 | import type { MetadataRoute } from 'next' |
4 | 5 |
|
5 | | -export default function sitemap(): MetadataRoute.Sitemap { |
6 | | - return [ |
| 6 | +export default async function sitemap(): Promise<MetadataRoute.Sitemap> { |
| 7 | + const base = env.NEXT_PUBLIC_CODEBUFF_APP_URL || 'http://localhost:3000' |
| 8 | + const toUrl = (path: string) => `${base}${path}` |
| 9 | + |
| 10 | + const items: MetadataRoute.Sitemap = [ |
7 | 11 | { |
8 | | - url: env.NEXT_PUBLIC_CODEBUFF_APP_URL || '/', |
| 12 | + url: toUrl('/'), |
9 | 13 | lastModified: new Date(), |
10 | 14 | changeFrequency: 'yearly', |
11 | 15 | priority: 1, |
12 | 16 | alternates: { |
13 | 17 | languages: { |
14 | | - pl: `${env.NEXT_PUBLIC_CODEBUFF_APP_URL}/pl`, |
| 18 | + pl: toUrl('/pl'), |
15 | 19 | }, |
16 | 20 | }, |
17 | 21 | }, |
| 22 | + { |
| 23 | + url: toUrl('/store'), |
| 24 | + lastModified: new Date(), |
| 25 | + changeFrequency: 'hourly', |
| 26 | + priority: 0.9, |
| 27 | + }, |
18 | 28 | ] |
| 29 | + |
| 30 | + // Include agent detail pages and publisher pages derived from cached store data |
| 31 | + try { |
| 32 | + const agents = await getCachedAgents() |
| 33 | + |
| 34 | + const seenPublishers = new Set<string>() |
| 35 | + for (const agent of agents) { |
| 36 | + const pubId = agent.publisher?.id |
| 37 | + if (pubId && !seenPublishers.has(pubId)) { |
| 38 | + items.push({ |
| 39 | + url: toUrl(`/publishers/${pubId}`), |
| 40 | + lastModified: new Date(agent.last_used || agent.created_at), |
| 41 | + changeFrequency: 'daily', |
| 42 | + priority: 0.7, |
| 43 | + }) |
| 44 | + seenPublishers.add(pubId) |
| 45 | + } |
| 46 | + |
| 47 | + if (pubId && agent.id && agent.version) { |
| 48 | + items.push({ |
| 49 | + url: toUrl(`/publishers/${pubId}/agents/${agent.id}/${agent.version}`), |
| 50 | + lastModified: new Date(agent.last_used || agent.created_at), |
| 51 | + changeFrequency: 'daily', |
| 52 | + priority: 0.8, |
| 53 | + }) |
| 54 | + } |
| 55 | + } |
| 56 | + } catch { |
| 57 | + // If fetching fails, fall back to base entries only |
| 58 | + } |
| 59 | + |
| 60 | + return items |
19 | 61 | } |
0 commit comments