Eleventy Plugin Baseline

A magic carpet ride

Documentation — Table of Contents

Deploy Under a Subpath

Serve your Baseline site from a subpath (e.g., /docs/) and keep links, assets, canonical URLs, and sitemap correct.

Prerequisites

Steps

  1. Set pathPrefix in Eleventy config.

    In eleventy.config.js, keep site.url to the origin and set pathPrefix to the subpath:

    import baseline, { config as baselineConfig } from "./_baseline/eleventy.config.js";
    
    export default function (eleventyConfig) {
      eleventyConfig.addPlugin(baseline());
    }
    
    export const config = {
      ...baselineConfig,
      pathPrefix: "/docs/",           // include leading/trailing slash
    };

    Eleventy rewrites root-relative URLs with pathPrefix, and Baseline’s head/sitemap modules read it via Eleventy.

  2. Keep site.url clean (origin only).

    In src/_data/site.js, use the origin only (no subpath). Canonicals and sitemap combine site.url + pathPrefix automatically:

    export default {
      title: "My Site",
      tagline: "My Site Tagline",
      url: process.env.URL || "http://localhost:8080/",   // no /docs here
      defaultLanguage: "en",
      noindex: false
    };
  3. Use root-relative asset/page links.

    Reference built assets and pages with leading slashes so Eleventy applies pathPrefix:

    <link rel="stylesheet" href="/assets/css/index.css">
    <script src="/assets/js/index.js" defer></script>
    <a href="/docs/getting-started/">Docs home</a>

    Avoid hardcoded full URLs with the subpath baked in.

  4. Build and inspect outputs.

    • Dev: npx rimraf dist/ && npm run dev
    • Build: npx rimraf dist/ && npm run build
    • Check dist/sitemap.xml and confirm URLs include /docs/.
    • Inspect a built page for <link rel="canonical"> and asset URLs that include /docs/.
  5. Preview with the subpath.

    • Serve dist/ from a subpath-capable server or use Eleventy’s preview with --pathprefix="/docs/" to spot broken links.
    • Click through pages and assets to confirm everything resolves under /docs/.

Notes

Common pitfalls

Previous: Custom Esbuild Targets

Next: Image Transform