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 sitemapIt requires site. Pass serializeSitemap as its serialize option:
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:
lastmodfrom<meta property="article:modified_time">, which docs pages with a last modified date have, like from the Git plugin.- The
hreflanglinks of docs pages with internationalization. - Pages with
noindexare 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:
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:
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:
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap-index.xmlRSS 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
