# SEO

Head tags, sitemaps and Open Graph images.

Every page has the head tags that search engines and social cards read. The [recommended preset](/config#recommendedpreset) also serves `robots.txt`, plus a sitemap and an RSS feed once you set the site's URL.

## Site URL [#site-url]

`site.baseUrl` is your deployed site's origin, like `https://docs.acme.dev`, without the [base path](/deploying#base-path). A site at `https://acme.github.io/docs/` sets `https://acme.github.io`, and the build adds the base path to URLs.

```ts title="vuesho.config.ts"
import { createSite, recommendedPreset } from "vuesho/config";
import { defineDocs } from "vuesho/content";

const docs = defineDocs();

export default createSite(docs.toSource())
  .plugins(recommendedPreset())
  .config({ site: { baseUrl: "https://docs.acme.dev" } }); // [!code highlight]
```

The canonical link, the sitemap, the RSS feed and the Open Graph images need full URLs, so a site without `site.baseUrl` has none of them, and the build warns.

## Head Tags [#head-tags]

Each page has these tags in its `<head>`, from its title, its description and the site name:

```html
<html lang="en" dir="ltr">
  <title>Installation | Acme Docs</title>
  <meta name="description" content="Add Acme to your project." />
  <meta property="og:title" content="Installation" />
  <meta property="og:description" content="Add Acme to your project." />
  <meta property="og:site_name" content="Acme Docs" />
  <link rel="alternate" type="text/markdown" href="/guide/install.md" />
  <!-- With `site.baseUrl`. -->
  <link rel="canonical" href="https://docs.acme.dev/guide/install" />
  <meta property="og:url" content="https://docs.acme.dev/guide/install" />
  <!-- With an Open Graph image. -->
  <meta property="og:image" content="https://docs.acme.dev/guide/install.webp" />
  <meta name="twitter:card" content="summary_large_image" />
  <!-- With translations, on a site with several languages. -->
  <link rel="alternate" hreflang="en" href="https://docs.acme.dev/guide/install" />
  <link rel="alternate" hreflang="zh-CN" href="https://docs.acme.dev/cn/guide/install" />
  <link rel="alternate" hreflang="x-default" href="https://docs.acme.dev/guide/install" />
  <!-- On a page left out of search engines. -->
  <meta name="robots" content="noindex" />
```

`head` in `.config()` adds tags to every page. An `html` or `body` tag sets that element's attributes, and Vuesho adds the base path to paths on your site:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).config({
  head: [
    { tag: "link", attrs: { rel: "icon", href: "/favicon.svg" } },
    { tag: "meta", attrs: { name: "theme-color", content: "#0a0a0a" } },
    { tag: "html", attrs: { class: "acme" } },
  ],
});
```

As a function, `head` returns each page's tags, from its `path`, `lang` and `pageData`:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).config({
  head({ path }) {
    // A post of the blog is an article for social cards.
    if (!path.startsWith("/blog/")) return [];
    return [{ tag: "meta", attrs: { property: "og:type", content: "article" } }];
  },
});
```

Your tag replaces the one with the same key:

- the `<title>`
- a `<meta>` by its `name`, `property` or `http-equiv`
- the canonical link
- an `hreflang` link

Tags in the config take priority over the defaults, plugins and the [theme](/theme#head-tags). A tag without a key is added.

## Sitemap [#sitemap]

`/sitemap.xml` lists every page, with its translations and last modified date, except pages with `noindex`. `getEntry` changes a page's entry, and `additionalEntries` adds URLs, like a custom page rendered on request:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).plugins(
  recommendedPreset({
    sitemap: {
      getEntry(entry, { page }) {
        if (!page?.url.startsWith("/blog/")) return entry;
        return { ...entry, changefreq: "weekly", images: [{ loc: "/blog/cover.png" }] };
      },
      additionalEntries: [{ loc: "/releases/v2", priority: 0.5 }],
    },
  }),
);
```

An entry takes the fields of the [sitemap protocol](https://www.sitemaps.org/protocol.html), and Google's `images`, `videos` and `news`. Write paths without the base path, which the sitemap adds.

### SitemapOptions

| Prop                 | Type                                                                                                               | Description                                                                                                                                                                                                           |
| -------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `path?`              | `string \| undefined`                                                                                              | The sitemap's path, without the base path. Default: `"/sitemap.xml"`                                                                                                                                                  |
| `filter?`            | `((env: PageEnv<AppShape>) => boolean) \| undefined`                                                               | Leaves out a page when it returns `false`. `env.page` is set for a content page, and `env.route` for a page route's page.                                                                                             |
| `getEntry?`          | `((this: Context<AppShape>, entry: SitemapEntry, env: PageEnv<AppShape>) => Awaitable<SitemapEntry>) \| undefined` | Gives the entry for a page the sitemap lists. `env.page` is set for a content page, and `env.route` for a page route's page. It receives the default entry, with the page's URL, last modified date and translations. |
| `additionalEntries?` | `SitemapEntry[] \| ((this: Context<AppShape>) => Awaitable<SitemapEntry[]>) \| undefined`                          | Entries for other URLs, like the pages of a custom page that renders on request.                                                                                                                                      |

For a sitemap that your own [plugin](/routes#api-routes) serves, `buildSitemap()` from `vuesho/config` writes the XML from entries.

## robots.txt [#robotstxt]

`/robots.txt` allows every crawler, and links to the sitemap. `rules` replaces its rules:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).plugins(
  recommendedPreset({
    robots: {
      rules: [
        { userAgent: "*", allow: "/", disallow: ["/private", "/*.pdf$"] },
        { userAgent: "GPTBot", disallow: "/" },
      ],
    },
  }),
);
```

### RobotsOptions

| Prop                 | Type                           | Description                                                                                                                                         |
| -------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `path?`              | `string \| undefined`          | The file's path. Crawlers only read `/robots.txt` at a domain's root. Default: `"/robots.txt"`                                                      |
| `rules?`             | `RobotsRule[] \| undefined`    | Default: `[{ userAgent: "*", allow: "/" }]`                                                                                                         |
| `sitemap?`           | `string \| false \| undefined` | The sitemap, as a site path or a full URL, or `false` for none. The file lists it by full URL, so a path is only listed when `site.baseUrl` is set. |
| `additionalContent?` | `string \| undefined`          | Text added at the end of the file, like a directive without an option.                                                                              |

A rule takes these fields:

### RobotsRule

| Prop          | Type                              | Description                                                                  |
| ------------- | --------------------------------- | ---------------------------------------------------------------------------- |
| `userAgent?`  | `string \| string[] \| undefined` | The crawlers, by user agent name. Default: `"*"`                             |
| `allow?`      | `string \| string[] \| undefined` | Paths without the base path, which the file adds. `*` and `$` are wildcards. |
| `disallow?`   | `string \| string[] \| undefined` | Paths without the base path, which the file adds. `*` and `$` are wildcards. |
| `crawlDelay?` | `number \| undefined`             | The seconds a crawler waits between requests. Only some crawlers read it.    |

<Callout type="warn" title="Sites Under a Base Path">
Crawlers read `robots.txt` only at a domain's root. A site at `/docs/` serves `/docs/robots.txt`, so copy its rules to the `robots.txt` at the domain's root.
</Callout>

## RSS Feed [#rss-feed]

`/rss.xml` lists the 20 newest pages with a date, from the frontmatter's `date` or from [Git](/markdown/collections#last-modified-dates). Each page links to it in its `<head>`, and each language has its own feed, like `/cn/rss.xml`:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).plugins(
  recommendedPreset({
    rss: {
      filter: ({ page }) => page.url.startsWith("/blog/"),
      channel: { title: "Acme Blog", image: "/logo.png" },
      getItem: (item) => ({ ...item, author: "team@acme.dev (Acme)" }),
      limit: 50,
    },
  }),
);
```

### RSSOptions

| Prop               | Type                                                                                                                                                           | Description                                                                                                                           |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `path?`            | `string \| undefined`                                                                                                                                          | The default language's feed. Other languages' feeds are under their prefixes. Default: `"/rss.xml"`                                   |
| `limit?`           | `number \| undefined`                                                                                                                                          | How many of the newest items a feed lists. Default: `20`                                                                              |
| `filter?`          | `((env: PageEnv<AppShape>) => boolean) \| undefined`                                                                                                           | Leaves out a page when it returns `false`. A feed lists content pages, so `env.page` is set.                                          |
| `channel?`         | `Partial<Omit<RSSChannel, "items">> \| ((this: Context<AppShape>, env: LangEnv<AppShape>) => Awaitable<Partial<Omit<RSSChannel, "items">>>) \| undefined`      | Fields for a feed's channel, over the defaults: the site's name and description in the language, its home page, and its language tag. |
| `getItem?`         | `((this: Context<AppShape>, item: RSSItem, env: LangEnv<AppShape> & { page: Page<string \| undefined, SourcePageData>; }) => Awaitable<RSSItem>) \| undefined` | Gives a page's item in a feed. It receives the default item, with the page data's title and description, the URL and the date.        |
| `additionalItems?` | `RSSItem[] \| ((this: Context<AppShape>, env: LangEnv<AppShape>) => Awaitable<RSSItem[]>) \| undefined`                                                        | Items for other URLs, added to every feed. A function gives the items for the feed of `lang`.                                         |

`rss: false` turns off the feed. For another feed that your own plugin serves, `buildRSS()` from `vuesho/config` writes the XML.

To serve the feed without the link in `<head>`, add `rssPlugin()` without its `head` hook:

```ts title="vuesho.config.ts"
import { rssPlugin } from "vuesho/config"; // [!code ++]

createSite(docs.toSource()).plugins(
  recommendedPreset({ rss: false }), // [!code highlight]
  { ...rssPlugin({ limit: 50 }), head: undefined }, // [!code ++]
);
```

## Excluded Pages [#excluded-pages]

There are two ways to leave a page out:

- The `filter` of the sitemap, the RSS feed, `llms.txt` or the [search](/search) leaves a page out of that output only, and a crawler can still follow a link to the page.
- `noindex` in the frontmatter, or from a plugin's `transformPage`, adds `<meta name="robots" content="noindex">` and leaves the page out of every output.

### Filtering by Frontmatter [#filtering-by-frontmatter]

A custom frontmatter field, like `unlisted`, can leave a page out of each file through `filter`. Add it to the [frontmatter schema](/markdown/collections#frontmatter-schema):

```ts title="vuesho.config.ts"
import { pageSchema } from "vuesho/schema"; // [!code ++]
import { z } from "zod"; // [!code ++]

const docs = defineDocs({
  docs: { schema: pageSchema.extend({ unlisted: z.boolean().default(false) }) }, // [!code ++]
});

export default createSite(docs.toSource()).plugins(
  // [!code highlight:6]
  recommendedPreset({
    sitemap: { filter: ({ page }) => !page?.data.unlisted },
    rss: { filter: ({ page }) => !page.data.unlisted },
    llms: { filter: ({ page }) => !page.data.unlisted },
    search: { filter: ({ page }) => !page.data.unlisted },
  }),
);
```

The sitemap's `filter` receives `{ page, route, path, lang }`, so it can also leave out [custom pages](/custom-pages) by `path`. A page left out of `llms` loses its `.md` file too.

### Setting `noindex` [#setting-noindex]

To set `noindex` on every page under a path, use a [plugin](/plugin-api)'s `transformPage` hook:

```ts title="vuesho.config.ts"
createSite(docs.toSource()).plugins(
  recommendedPreset(),
  // [!code ++:5]
  {
    name: "site:noindex",
    transformPage: (_data, { path }) =>
      path.startsWith("/internal/") ? { noindex: true } : undefined,
  },
);
```

A custom page sets it with `definePage({ data: { noindex: true } })`. A page shown in the [fallback language](/i18n#fallback-language) already has `noindex`.

## Open Graph Images [#open-graph-images]

`ogImagePlugin()` draws a 1200 by 630 pixel image for each page, with its title, its description and the site name, for social cards. Here is this page's image:

<img src="/seo.webp" width="1200" height="630" alt="This page's Open Graph image, with its title and description" />

`npm create vuesho` adds the plugin to a new site. To add it to an existing site, follow these steps.

### Install Takumi [#install-takumi-step]

[Takumi](https://takumi.kane.tw) renders the images:

```npm
npm i takumi-js
```

### Add the Plugin [#add-the-plugin-step]

The image tags need full URLs, so set the [site URL](#site-url):

```ts title="vuesho.config.ts"
import { ogImagePlugin } from "vuesho/og"; // [!code ++]

export default createSite(docs.toSource())
  .plugins(
    recommendedPreset(),
    ogImagePlugin(), // [!code ++]
  )
  .config({ site: { name: "Acme Docs", baseUrl: "https://docs.acme.dev" } }); // [!code highlight]
```

### OGImageOptions

| Prop       | Type                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Description                                                                                                                                                                                                                                                                                     |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `width?`   | `number \| undefined`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The image width, in pixels. Default: `1200`                                                                                                                                                                                                                                                     |
| `height?`  | `number \| undefined`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The image height, in pixels. Default: `630`                                                                                                                                                                                                                                                     |
| `filter?`  | `((env: PageEnv<AppShape>) => boolean) \| undefined`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Picks the pages that get an image. A page it returns `false` for has none.                                                                                                                                                                                                                      |
| `options?` | `Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format?: "png"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "jpeg"; quality?: number; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "webp"; quality?: number; lossless?: boolean; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "ico"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "raw"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format?: "png"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "jpeg"; quality?: number; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "webp"; quality?: number; lossless?: boolean; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "ico"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "raw"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format?: "png"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "jpeg"; quality?: number; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "webp"; quality?: number; lossless?: boolean; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "ico"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "raw"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format?: "png"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "jpeg"; quality?: number; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "webp"; quality?: number; lossless?: boolean; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "ico"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "raw"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| ((env: LangEnv<AppShape>) => Awaitable<Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format?: "png"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "jpeg"; quality?: number; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "webp"; quality?: number; lossless?: boolean; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "ico"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "raw"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format?: "png"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "jpeg"; quality?: number; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "webp"; quality?: number; lossless?: boolean; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "ico"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "raw"; } & RenderExtras, "images" \| "css"> & CssOptions & SharedRenderExtras, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format?: "png"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "jpeg"; quality?: number; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "webp"; quality?: number; lossless?: boolean; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "ico"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, WrapperOptions \| "format" \| "quality" \| "lossless"> & { format: "raw"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format?: "png"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "jpeg"; quality?: number; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "webp"; quality?: number; lossless?: boolean; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "ico"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang"> \| Omit<Omit<Omit<RenderOptions$1, "format" \| "quality" \| "lossless" \| WrapperOptions> & { format: "raw"; } & RenderExtras, "images" \| "css"> & CssOptions & Omit<SharedRenderExtras, "renderer"> & ManagedRendererOptions, "format" \| "width" \| "height" \| "lang">>) \| undefined` | Options for Takumi's `render()`, like the images' fonts. It can be a function of the language, called once per language on its first image: `({ lang }) => ({ fonts: googleFonts(...) })`. Without `fonts`, a language of a script other than Latin draws with its Noto font from Google Fonts. |
| `format?`  | `"png" \| "webp" \| undefined`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | The image format, which ends the image URL, like `/guide/install.png`. Default: `"webp"`                                                                                                                                                                                                        |

### Open an Image [#open-an-image-step]

Run `vuesho dev`, and open a page's URL with `.webp` added, like `/guide/install.webp`, or `/index.webp` for `/`.

### Pages With an Image [#pages-with-an-image]

Every page has an image, including custom pages and plugin pages, unless it has `noindex` or a `filter` leaves it out:

```ts title="vuesho.config.ts"
ogImagePlugin({ filter: ({ path }) => !path.startsWith("/internal/") });
```

To use an image of your own on a page, leave the page out with `filter`, and write its tags with [`head`](#head-tags). A social card reads a full URL only:

```ts title="vuesho.config.ts"
createSite(docs.toSource())
  .plugins(recommendedPreset(), ogImagePlugin({ filter: ({ path }) => path !== "/" }))
  .config({
    head({ path }) {
      if (path !== "/") return [];
      return [
        {
          tag: "meta",
          attrs: { property: "og:image", content: "https://docs.acme.dev/banner.png" },
        },
        { tag: "meta", attrs: { name: "twitter:card", content: "summary_large_image" } },
      ];
    },
  });
```

### Texts [#texts]

The image shows the page's title and description. `ogImage` in the frontmatter replaces them:

```md title="content/reference/client.md"
---
title: Client
ogImage:
  title: "API: Client"
  description: The client of the Acme API
---
```

To set the texts of many pages, use a plugin's `transformPage`, which declares `ogImage` in its types:

```ts title="vuesho.config.ts"
import type { AppShape, Plugin } from "vuesho/config";

const referenceImages: Plugin<AppShape, { pageData: { ogImage?: { title?: string } } }> = {
  name: "site:og",
  transformPage(data, { page }) {
    if (!page?.path.startsWith("reference/")) return;
    return { ogImage: { title: `API: ${data.title}` } };
  },
};

createSite(docs.toSource()).plugins(recommendedPreset(), ogImagePlugin(), referenceImages);
```

### Template [#template]

The image is a Vue component, the theme's `og-image` [body](/theme#views-and-page-bodies). To use your own template, replace it:

```ts title="src/theme.ts"
import { defineTheme } from "vuesho/theme";
import defaultTheme from "vuesho/theme/default";

export default defineTheme({
  extends: defaultTheme,
  bodies: { "og-image": () => import("./OGImage.vue") }, // [!code highlight]
});
```

The template renders without your site's CSS, so style its elements with `style`:

```vue title="src/OGImage.vue"
<script setup lang="ts">
import type { OGImageProps } from "vuesho/og";

// The texts of `ogImage`, or the page's title and description.
const { title, description, site } = defineProps<OGImageProps>();
</script>

<template>
  <div
    :lang="site.lang"
    :dir="site.dir"
    style="
      display: flex;
      flex-direction: column;
      width: 100%;
      height: 100%;
      padding: 64px;
      color: white;
      background: #0a0a0a;
    "
  >
    <p style="margin: 0; font-size: 72px; font-weight: 700">
      {{ title }}
    </p>
    <p style="font-size: 36px; color: #a3a3a3">
      {{ description }}
    </p>
    <p style="margin-top: auto; font-size: 36px">{{ site.name }}</p>
  </div>
</template>
```

### OGImageProps

| Prop           | Type                                                                          | Description                                                                                   |
| -------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| `title?`       | `string \| undefined`                                                         | The title to draw: `ogImage.title`, or the page's title.                                      |
| `description?` | `string \| undefined`                                                         | The description to draw: `ogImage.description`, or the page's description.                    |
| `page`         | `{ url: string; pageData: PageData; }`                                        | The page the image is for, with its URL (without the base path) and its page data.            |
| `site`         | `{ name?: string; description?: string; lang: string; dir: "ltr" \| "rtl"; }` | The site in the page's language, with its name, description, language tag and text direction. |

Takumi loads an image from a full URL or a data URL, not from a path like `/logo.png`. Import a project file as a data URL with `?inline`:

```vue title="src/OGImage.vue"
<script setup lang="ts">
import logo from "./logo.png?inline";
</script>

<template>
  <img :src="logo" width="64" height="64" />
</template>
```

### Fonts [#fonts]

The images draw Latin text with Takumi's Geist, and other scripts with their Noto font from Google Fonts. To use other fonts, or for an offline build, give `fonts` in `options`:

```ts tab="Google Fonts" title="vuesho.config.ts"
import { googleFonts } from "takumi-js/helpers";
import { ogImagePlugin } from "vuesho/og";

ogImagePlugin({
  // Downloads only the characters the pages use.
  options: ({ lang }) => ({
    fonts: googleFonts(lang === "ja" ? ["Inter", "Noto Sans JP"] : ["Inter"]),
  }),
});
```

```ts tab="Font files" title="vuesho.config.ts"
import { readFile } from "node:fs/promises";
import { ogImagePlugin } from "vuesho/og";

createSite(docs.toSource()).plugins(
  ogImagePlugin({
    options: async () => ({
      fonts: [{ name: "JetBrains Mono", data: await readFile("fonts/JetBrainsMono.ttf") }],
    }),
  }),
  // A server that draws images reads the font from its output.
  { name: "site:fonts", serverFiles: () => ["fonts/JetBrainsMono.ttf"] },
);
```

A template sets a font from `options` with `fontFamily`, like `Playfair Display` for blog posts:

```ts tab="vuesho.config.ts"
import { googleFonts } from "takumi-js/helpers";
import { ogImagePlugin } from "vuesho/og";

ogImagePlugin({
  options: () => ({ fonts: googleFonts(["Inter", "Playfair Display"]) }), // [!code highlight]
});
```

```vue tab="src/OGImage.vue"
<script setup lang="ts">
import type { OGImageProps } from "vuesho/og";

const { page } = defineProps<OGImageProps>();
const font = page.url.startsWith("/blog/") ? "Playfair Display" : "Inter"; // [!code highlight]
</script>

<template>
  <div
    :style="{ display: 'flex', width: '100%', height: '100%', padding: '64px', fontFamily: font }"
  >
    <p style="margin: 0; font-size: 72px; font-weight: 700">{{ page.pageData.title }}</p>
  </div>
</template>
```

### Deployment [#deployment]

Build on the operating system and CPU architecture you deploy to, so the native build of Takumi matches the server.

<Callout type="warn" title="Cloudflare Workers' CPU Limit">
Cloudflare Workers' free plan limits a request to 10 ms of CPU time, which drawing an image can exceed. Keep the pages static there, so the build draws their images.
</Callout>
