Eleventy Plugin Baseline

A magic carpet ride

Table of Contents

head-core

Note: The options API is still evolving; expect tweaks as the project grows.

What it does

head-core injects <head> elements — canonical, meta, Open Graph, Twitter, links, and scripts — into any template that contains a <baseline-head> tag. It merges site-wide defaults from _data/head.js with per-page front matter, then replaces the tag with the rendered elements via PostHTML.

Defaults

  • Head tag: <baseline-head> — the marker that gets replaced.
  • Data key: head — the front matter key for per-page overrides.
  • Canonical: built from page.url, absolutized with site.url (or URL/DEPLOY_URL env vars) + pathPrefix. Override per page with head.canonical.
  • Robots: omitted unless noindex: true is set in front matter (emits noindex, nofollow).
  • OG/Twitter: site-wide defaults from _data/head.js; per-page overrides via head.openGraph / head.twitter.

Options

Option Type Default Description
verbose boolean Baseline verbose Extra logging from the head builder.

Other head-core options are internal for now.

How it works

  1. Content map caching.

    On the eleventy.contentMap event, head-core builds an inputPath↔url lookup. This powers canonical resolution — even when a page doesn’t have an explicit URL in its data.

  2. Computed head data.

    Adds eleventyComputed.page.head, which calls a shared buildHead function. This merges site data, _data/head.js, and page-level head: front matter into a single object per page.

  3. HTML transform.

    A PostHTML plugin finds <baseline-head> and replaces it with the rendered elements. It reuses page.head when available (from step 2), or calls buildHead directly. Element order is preserved: base meta, title, canonical link, links/scripts, then OG/Twitter meta.

Tips

  • <baseline-head> must be inside <head>. If it’s missing, no elements are injected — no error, just silence.
  • Set global defaults in _data/head.js; override per page with head: in front matter. Page-level values win.
  • For absolute canonicals and og:url, set site.url in your data or use URL/DEPLOY_URL env vars. Without a URL, canonicals will be relative.
  • noindex: true in front matter emits a robots meta tag and excludes the page from the sitemap (via sitemap-core).
  • See Head & SEO Basics for a guided setup, Deployment URL Checks for URL hygiene, and Custom Social Previews for OG/Twitter customization.

Peer deps

None — uses PostHTML bundled with Eleventy.

Previous: assets-postcss

Next: multilang-core