Color mode

Search notes

Filter with tag:, lang:, or path:.

Customize SEO

seo lets a plugin supply metadata, sitemap, robots, and feed generation. The first plugin in resolved order that declares seo wins, so a custom plugin can wrap the official helpers and override one method.

Keep @riebeckite/plugin-seo registered when you still want its endpoints for sitemap.xml, feeds, and robots.txt.

ts
import { definePlugin } from "@riebeckite/core";
import {
  buildAbsoluteUrl,
  buildArticleSeo,
  buildPostUrl,
  buildWebsiteSeo,
  getDescription,
  getEntryPublishedTime,
  getEntryUpdatedTime,
  getHtmlLanguage,
  renderAtomFeed,
  renderJsonFeed,
  renderRobots,
  renderRssFeed,
  renderSitemap,
} from "@riebeckite/plugin-seo";
 
export function titleSuffix(suffix = " | Example") {
  return definePlugin({
    name: "seo-title-suffix",
    order: -10,
    seo: {
      buildArticleSeo(config, permalink, post, headTags, language) {
        const metadata = buildArticleSeo(
          config,
          permalink,
          post,
          headTags,
          language,
        );
        return { ...metadata, title: `${metadata.title}${suffix}` };
      },
      buildWebsiteSeo,
      buildAbsoluteUrl,
      buildPostUrl,
      getDescription,
      getEntryPublishedTime,
      getEntryUpdatedTime,
      getHtmlLanguage,
      renderSitemap,
      renderRobots,
      renderRssFeed,
      renderAtomFeed,
      renderJsonFeed,
    },
  });
}

order: -10 places this plugin before the official seo plugin. The dependency resolver still puts providers before consumers when capabilities are involved.

This example changes article titles only. Wrap buildWebsiteSeo the same way if the suffix should also apply to website pages.

If you change a title that also appears in JSON-LD, update jsonLd in the returned metadata as well. Otherwise the page title and structured data disagree.


Back to Plugin Recipes · Plugin API