Sitemap

Generate a sitemap.xml for your Fumapress site.

Installation

This plugin is included in fumapress.

Set site.baseUrl in your config, sitemap entries must be fully-qualified URLs:

press.config.tsx
import { defineConfig } from "fumapress";
import { sitemapPlugin } from "fumapress/plugins/sitemap";

export default defineConfig({
  site: {
    baseUrl: "https://example.com",
  },
})
  .plugins(sitemapPlugin());

The plugin creates a sitemap at /sitemap.xml.

By default, every page from your content source is included with a priority of 0.8, and static routes are included as well.

Options

path

Change the sitemap route. Default: "/sitemap.xml".

press.config.tsx
import { sitemapPlugin } from "fumapress/plugins/sitemap";

export default defineConfig({
  // ...
}).plugins(
  sitemapPlugin({
    path: "/sitemap.xml",
  }),
);

getEntry

Customize or exclude entries. Return undefined to omit a page:

press.config.tsx
import { sitemapPlugin } from "fumapress/plugins/sitemap";

export default defineConfig({
  // ...
}).plugins(
  sitemapPlugin({
    async getEntry(page) {
      if (page.path.startsWith("drafts/")) return;

      return {
        loc: this.absoluteUrl(page.url),
        lastmod: page.data.lastModified,
        changefreq: "weekly",
        priority: page.path === "index" ? 1 : 0.8,
        alternates: await this.getPageAlternates(page),
      };
    },
  }),
);

getEntry receives the app context as this, so you can access siteConfig, absoluteUrl(), and other plugin APIs.

Each entry supports the standard sitemap fields (loc, lastmod, changefreq, priority), plus the Google extensions:

  • alternates: alternate language versions of the page, written as xhtml:link hreflang elements. this.getPageAlternates(page) returns the translations of a page.
  • images: images on the page (image extension).
  • videos: videos on the page (video extension).
  • news: news article metadata (Google News extension), at most one per URL.

An entry with a video looks like:

{
  loc: "https://example.com/videos/intro",
  videos: [
    {
      thumbnail_loc: "https://example.com/thumbs/intro.jpg",
      title: "Introducing Fumapress",
      description: "A quick tour of the framework.",
      content_loc: "https://example.com/videos/intro.mp4",
    },
  ],
}

additionalEntries

Append extra URLs that are not backed by content pages. Each entry's loc must be a fully-qualified URL:

press.config.tsx
import { sitemapPlugin } from "fumapress/plugins/sitemap";

export default defineConfig({
  // ...
}).plugins(
  sitemapPlugin({
    additionalEntries: [
      {
        loc: "https://example.com/changelog",
        changefreq: "weekly",
        priority: 0.5,
      },
    ],
  }),
);

Pass a function to compute entries at build time:

press.config.tsx
sitemapPlugin({
  additionalEntries() {
    return [
      {
        loc: this.absoluteUrl("/rss.xml"),
        changefreq: "daily",
      },
    ];
  },
});

Custom Sitemaps

For additional sitemaps, the buildSitemap function serializes entries to XML, serve it from your own API route the same way as a custom RSS feed.

Last updated on

On this page