Fumadocs

SEO

Sitemap, robots.txt and RSS feeds.

Sitemap

Use @astrojs/sitemap to list every page of your site, including docs pages and custom pages.

npx astro add sitemap

It requires site. Pass serializeSitemap as its serialize option:

astro.config.mjs
import { defineConfig } from 'astro/config';
import fumadocs, { serializeSitemap } from '@fumadocs/astro'; 
import sitemap from '@astrojs/sitemap';

export default defineConfig({
  site: 'https://example.com', 
  integrations: [fumadocs(), sitemap({ serialize: serializeSitemap })], 
});

It reads the <head> of each built page:

  • lastmod from <meta property="article:modified_time">, which docs pages with a last modified date have, like from the Git plugin.
  • The hreflang links of docs pages with internationalization.
  • Pages with noindex are left out, like the pages shown in the fallback language.

Custom pages can render the same tags in HomeLayout's head slot. To add hreflang links to them, pass the languages to the i18n option:

astro.config.mjs
sitemap({
  serialize: serializeSitemap,
  i18n: {
    defaultLocale: 'en',
    // language -> `hreflang`
    locales: { en: 'en', cn: 'zh-CN' },
  },
});

To change the items further, call it in your own serialize:

astro.config.mjs
sitemap({
  async serialize(item) {
    const result = await serializeSitemap(item);
    if (result?.url.includes('/docs/')) result.priority = 0.8;
    return result;
  },
});

robots.txt

Put it in public/, with the sitemap:

public/robots.txt
User-agent: *
Allow: /

Sitemap: https://example.com/sitemap-index.xml

RSS Feed

See RSS Feed. Add the <link> in your Fumadocs config's head component.

page.data has no lastModified, add a date to the frontmatter schema, like date: z.coerce.date(), and use page.data.date.

How is this guide?

Last updated on