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
- Baseline installed; assets pipeline enabled.
site.urlset 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
-
Set
pathPrefixin Eleventy config.In
eleventy.config.js, keepsite.urlto the origin and setpathPrefixto 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. -
Keep
site.urlclean (origin only).In
src/_data/site.js, use the origin only (no subpath). Canonicals and sitemap combinesite.url+pathPrefixautomatically:export default { title: "My Site", tagline: "My Site Tagline", url: process.env.URL || "http://localhost:8080/", // no /docs here defaultLanguage: "en", noindex: false }; -
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.
-
Build and inspect outputs.
- Dev:
npx rimraf dist/ && npm run dev - Build:
npx rimraf dist/ && npm run build - Check
dist/sitemap.xmland confirm URLs include/docs/. - Inspect a built page for
<link rel="canonical">and asset URLs that include/docs/.
- Dev:
-
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/.
- Serve
Notes
- Don’t append the subpath to
site.url; usepathPrefixfor the path segment. - If you move back to root hosting, clear
pathPrefixto avoid double paths. - Watch for hardcoded absolute URLs; prefer root-relative so Eleventy can rewrite with
pathPrefix.
Common pitfalls
- Mixing subpath into
site.urland also settingpathPrefix→ 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.jsinstead of/assets/js/index.js) preventspathPrefixfrom applying. - Building without
pathPrefixand then deploying under a subpath breaks links; build/preview with the samepathPrefixyou plan to deploy.
Previous: Custom Esbuild Targets
Next: Image Transform