Skip to Content
Fumadocs

Takumi

Integrate Takumi for framework agnostic and fast metadata image generation.

Installation

npm install takumi-js

Metadata 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) };
}

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:

src/pages/og/docs/[...slug]/image.webp.ts
import type { APIRoute, GetStaticPaths, InferGetStaticPropsType } from 'astro';
import { generateOGImage } from 'fumadocs-ui/og/takumi';
import { source } from '@/lib/source';
import { appName } from '@/lib/shared';

export const prerender = true;

export const getStaticPaths = (() => {
  return source.getPages().map((page) => ({
    params: { slug: decodeURI(page.slugs.join('/')) || undefined },
    props: { page },
  }));
}) satisfies GetStaticPaths;

export const GET: APIRoute<InferGetStaticPropsType<typeof getStaticPaths>> = ({
  props: { page },
}) => {
  return generateOGImage({
    title: page.data.title,
    description: page.data.description,
    site: appName,
    format: 'webp',
  });
};

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?

Last updated on