Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import type { MetadataRoute } from 'next'; |
| 2 | import { |
| 3 | source, |
| 4 | getReferenceSource, |
| 5 | examplesSource, |
| 6 | toolkitsSource, |
| 7 | knowledgeBaseSource, |
| 8 | changelogEntries, |
| 9 | dateToChangelogUrl, |
| 10 | } from '@/lib/source'; |
| 11 | import { getAllToolkitsSync } from '@/lib/toolkit-data'; |
| 12 | import { getLocalKnowledgeDiscoveryPaths } from '@/lib/knowledge/discovery'; |
| 13 | import { getPageLastUpdated } from '@/lib/content-freshness'; |
| 14 | |
| 15 | const baseUrl = 'https://docs.composio.dev'; |
| 16 | |
| 17 | function getChangelogDate(entry: (typeof changelogEntries)[number]): string | null { |
| 18 | if (typeof entry.date === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(entry.date)) { |
| 19 | return entry.date; |
| 20 | } |
| 21 | |
| 22 | const filename = entry.info?.path ?? ''; |
| 23 | const match = filename.match(/^(\d{2})-(\d{2})-(\d{2})(?:-|\.)/); |
| 24 | return match ? `20${match[3]}-${match[1]}-${match[2]}` : null; |
| 25 | } |
| 26 | |
| 27 | export default async function sitemap(): Promise<MetadataRoute.Sitemap> { |
| 28 | const knowledgeDiscoveryPaths = await getLocalKnowledgeDiscoveryPaths(); |
| 29 | const docsPages = source.getPages().map((page) => ({ |
| 30 | url: `${baseUrl}${page.url}`, |
| 31 | })); |
| 32 | |
| 33 | // Use async reference source to include OpenAPI-generated API reference pages |
| 34 | const referenceSource = await getReferenceSource(); |
| 35 | const referencePages = referenceSource.getPages().map((page: { url: string }) => ({ |
| 36 | url: `${baseUrl}${page.url}`, |
| 37 | })); |
| 38 | |
| 39 | const examplesPages = examplesSource.getPages().map((page) => ({ |
| 40 | url: `${baseUrl}${page.url}`, |
| 41 | })); |
| 42 | |
| 43 | const knowledgeBasePages = knowledgeBaseSource.getPages().map((page) => ({ |
| 44 | url: `${baseUrl}${page.url}`, |
| 45 | })); |
| 46 | const knowledgeDiscoveryPages = knowledgeDiscoveryPaths |
| 47 | .filter((path) => path !== '/kb/search') |
| 48 | .map((path) => ({ |
| 49 | url: `${baseUrl}${path}`, |
| 50 | })); |
| 51 | |
| 52 | // MDX toolkit pages |
| 53 | const toolkitsMdxPages = toolkitsSource.getPages().map((page) => ({ |
| 54 | url: `${baseUrl}${page.url}`, |
| 55 | })); |
| 56 | |
| 57 | // JSON toolkit pages (dynamically generated from toolkits.json) |
| 58 | const toolkitsJsonPages = getAllToolkitsSync().map((toolkit) => ({ |
| 59 | url: `${baseUrl}/toolkits/${toolkit.slug}`, |
| 60 | })); |
| 61 | |
| 62 | // Changelog pages (deduplicate by date since multiple entries can share the same date) |
| 63 | const uniqueChangelogDates = [ |
| 64 | ...new Set(changelogEntries.map(getChangelogDate).filter((date): date is string => date !== null)), |
| 65 | ]; |
| 66 | const changelogPages = uniqueChangelogDates.map((date) => ({ |
| 67 | url: `${baseUrl}${dateToChangelogUrl(date)}`, |
| 68 | })); |
| 69 | |
| 70 | const pages = [ |
| 71 | { url: baseUrl }, |
| 72 | { url: `${baseUrl}/docs/changelog` }, |
| 73 | ...docsPages, |
| 74 | ...referencePages, |
| 75 | ...examplesPages, |
| 76 | ...knowledgeBasePages, |
| 77 | ...knowledgeDiscoveryPages, |
| 78 | ...toolkitsMdxPages, |
| 79 | ...toolkitsJsonPages, |
| 80 | ...changelogPages, |
| 81 | ]; |
| 82 | |
| 83 | return Promise.all( |
| 84 | Array.from(new Map(pages.map((page) => [page.url, page])).values()).map(async (page) => { |
| 85 | const lastModified = await getPageLastUpdated(new URL(page.url).pathname); |
| 86 | return lastModified ? { ...page, lastModified } : page; |
| 87 | }), |
| 88 | ); |
| 89 | } |