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 { markdownAlternates } from '@/lib/markdown-alternates'; |
| 2 | import { DocsBody, DocsPage, DocsTitle } from 'fumadocs-ui/layouts/docs/page'; |
| 3 | import { notFound } from 'next/navigation'; |
| 4 | import { getMDXComponents } from '@/mdx-components'; |
| 5 | import type { Metadata } from 'next'; |
| 6 | import { createRelativeLink } from 'fumadocs-ui/mdx'; |
| 7 | import { PageActions } from '@/components/page-actions'; |
| 8 | import { EditOnGitHub } from '@/components/edit-on-github'; |
| 9 | import { getOgImageUrl } from '@/lib/source'; |
| 10 | import { getKnowledgeDisplayDescription } from '@/lib/knowledge/display'; |
| 11 | |
| 12 | type Source = typeof import('./source').examplesSource; |
| 13 | |
| 14 | export function createDocsPage(source: Source, contentDir: string = 'content/docs') { |
| 15 | return async function Page({ params }: { params: Promise<{ slug?: string[] }> }) { |
| 16 | const { slug } = await params; |
| 17 | const page = source.getPage(slug); |
| 18 | if (!page) notFound(); |
| 19 | |
| 20 | const MDX = page.data.body; |
| 21 | |
| 22 | return ( |
| 23 | <DocsPage |
| 24 | toc={page.data.toc} |
| 25 | full={page.data.full} |
| 26 | footer={{ enabled: false }} |
| 27 | tableOfContentPopover={{ enabled: false }} |
| 28 | > |
| 29 | <DocsTitle>{page.data.title}</DocsTitle> |
| 30 | <PageActions path={page.url} /> |
| 31 | <DocsBody> |
| 32 | <MDX |
| 33 | components={getMDXComponents({ |
| 34 | a: createRelativeLink(source, page), |
| 35 | })} |
| 36 | /> |
| 37 | <EditOnGitHub path={`docs/${contentDir}/${page.path}`} /> |
| 38 | </DocsBody> |
| 39 | </DocsPage> |
| 40 | ); |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | export function createGenerateStaticParams(source: Source) { |
| 45 | return function generateStaticParams() { |
| 46 | return source.generateParams(); |
| 47 | }; |
| 48 | } |
| 49 | |
| 50 | export function createGenerateMetadata(source: Source, section: string = 'docs') { |
| 51 | return async function generateMetadata({ |
| 52 | params, |
| 53 | }: { |
| 54 | params: Promise<{ slug?: string[] }>; |
| 55 | }): Promise<Metadata> { |
| 56 | const { slug } = await params; |
| 57 | const page = source.getPage(slug); |
| 58 | if (!page) notFound(); |
| 59 | |
| 60 | const description = page.data.description |
| 61 | ? getKnowledgeDisplayDescription(page.data.description) |
| 62 | : page.data.description; |
| 63 | const ogImage = getOgImageUrl(section, page.slugs, page.data.title, description); |
| 64 | |
| 65 | return { |
| 66 | title: page.data.title, |
| 67 | description, |
| 68 | alternates: markdownAlternates(page.url), |
| 69 | openGraph: { |
| 70 | images: [ogImage], |
| 71 | }, |
| 72 | twitter: { |
| 73 | card: 'summary_large_image', |
| 74 | images: [ogImage], |
| 75 | }, |
| 76 | }; |
| 77 | }; |
| 78 | } |