Eleventy Plugin Baseline

A magic carpet ride

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

  • Baseline installed; assets pipeline enabled.
  • site.url set to the production origin (no trailing slash, no subpath).
  • You deploy to a subpath (e.g., GitHub Pages project site, reverse proxy, Netlify subdir).

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 async 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

  • Don’t append the subpath to site.url; use pathPrefix for the path segment.
  • If you move back to root hosting, clear pathPrefix to avoid double paths.
  • Watch for hardcoded absolute URLs; prefer root-relative so Eleventy can rewrite with pathPrefix.

Common pitfalls

  • Mixing subpath into site.url and also setting pathPrefix → double /docs/docs/ in links and sitemap.
  • Hardcoded absolute URLs (e.g., https://example.com/docs/...) that won’t rewrite; use root-relative.
  • Missing leading slash on assets/links (assets/js/index.js instead of /assets/js/index.js) prevents pathPrefix from applying.
  • Building without pathPrefix and then deploying under a subpath breaks links; build/preview with the same pathPrefix you plan to deploy.