Takumi
Integrate Takumi for framework agnostic and fast metadata image generation.
Installation
npm install takumi-jsMetadata Image
Add a function that returns the image URL of a page, and reference the image in the metadata of docs pages:
import { createGetUrl } from 'fumadocs-core/source';
const getImageUrl = createGetUrl('/og/docs');
export function getPageImageUrl(page: { slugs: string[]; locale?: string }) {
const segments = [...page.slugs, 'image.webp'];
return { segments, url: getImageUrl(segments, page.locale) };
}import { getPageImageUrl } from '@/lib/shared';
// Somewhere in your page component
return (
<DocsPage toc={page.data.toc}>
<meta property="og:image" content={getPageImageUrl(page).url} />
{/* ... */}
</DocsPage>
);The image of /docs/my-page is at /og/docs/my-page/image.webp, since WebP images are smaller than PNG ones. To generate PNG, use image.png and format: 'png' instead.
Then create a route to generate the images:
import { source } from '@/lib/source';
import { generateOGImage } from 'fumadocs-ui/og/takumi';
import { ApiContext } from 'waku/router';
export async function GET(_: Request, { params }: ApiContext<'/og/docs/[...slugs]/image.webp'>) {
const page = source.getPage(params.slugs);
if (!page) return new Response(undefined, { status: 404 });
return generateOGImage({
title: page.data.title,
description: page.data.description,
site: 'My App',
format: 'webp',
});
}
export async function getConfig() {
const pages = source
.generateParams()
.map((item) => (item.lang ? [item.lang, ...item.slug] : item.slug));
return {
render: 'static' as const,
staticPaths: pages,
} as const;
}Takumi bundles the full-axis (100-900) Geist and Geist Mono fonts, so no font setup is needed.
See Takumi's Documentation for advanced usage.
Other Templates
See Takumi Templates for the available templates.
How is this guide?
