Search indexing and social share cards both live or die by the metadata in <head>. xfm-plugin-seo injects canonical links, Open Graph, Twitter Card, and JSON-LD into every rendered page — and it respects tags your template already wrote, never duplicating anything.
What it solves
These tags are tedious to hand-write and vary from page to page: posts need publish and modified times, tags, and an author; the home page needs site-level structured data. The plugin distinguishes automatically — posts get og:type: article and Article structured data, the home page gets WebSite, and when site search is configured the home page also carries a SearchAction.
Install and configure
npm i -D xfm-plugin-seo// xfm.config.mjs
export default {
seo: {
image: '/og.png', // default share image; relative paths become absolute
twitter: '@handle', // emits twitter:site
jsonLd: true, // set false to disable JSON-LD entirely
},
};Output and fields
The plugin writes no files; it inserts one block before each page's </head>:
<link rel="canonical">: the page's absolute URL by default, overridable via front-mattercanonical;- Open Graph:
og:title/description/url/site_name/locale, plusarticle:published_time,article:modified_time, and onearticle:tagper tag on posts; the pageimageor configured default becomesog:image; - Twitter Card:
summary_large_imagewith an image,summarywithout;twitter:siteappears whentwitteris set; - JSON-LD:
Articlefor posts (withauthorfromsite.author,publisher,keywords),WebSitefor the home page.
On multilingual sites, pages with translations automatically gain hreflang links and og:locale:alternate, with x-default pointing at the default language; single-language sites emit none of these, so their output is unchanged. The description falls back in order: front-matter description → first 160 characters of the excerpt → site.description.
Page-level switches: image overrides the share image, canonical overrides the canonical URL, noindex: true emits noindex, follow, and seo: false skips the page entirely.
Notes
- If your template already writes
rel="canonical"orog:title, the plugin leaves those parts alone, so themes can take over. - Date-only values are emitted as midnight UTC to avoid off-by-one-day parsing differences between environments.
- Pair with the sitemap plugin to cover crawl entry points too; background in SEO and site search.
Comments