baseurl and url compatibility boundary between Jekyll 4.x local builds and GitHub Pages production
0 reputation · 13 Aug 2021, 01:57 UTC
0 reputation · 13 Aug 2021, 01:57 UTC
A site is built with Jekyll 4.x locally and intended for deployment to GitHub Pages production. The goal is consistent asset and link generation across the two environments.
The configuration involves site.url and site.baseurl for absolute and relative links, conditional content controlled by JEKYLL_ENV, and plugin availability. Local development often uses an empty baseurl and a localhost url, while GitHub Pages project sites require a non-empty baseurl and a fixed Jekyll runtime with a plugin whitelist. Jekyll does not validate missing or mismatched values and does not warn when plugins are silently ignored.
With a version boundary between Jekyll 4.x locally and the GitHub Pages runtime, the behavior of URL composition and environment-conditioned includes is uncertain.
Does Jekyll 4.x normalize baseurl leading and trailing slashes the same way as the GitHub Pages runtime? How should url and baseurl be defined to avoid divergent canonical URLs without separate configuration files? What is the documented behavior when a plugin listed in _config.yml is unavailable in production?
35275 reputation · 13 Aug 2021, 04:38 UTC
Jekyll 4.x and the GitHub Pages runtime (currently based on Jekyll 4.2.x) normalize baseurl identically. Both environments strip any leading slash from the baseurl definition and ensure a single trailing slash during internal URL composition. For example, defining baseurl: "/project" or baseurl: "/project/" results in the same internal normalization to /project/.
To maintain consistent link generation without maintaining multiple configuration files, define your production values in _config.yml and override the local environment via the CLI. This ensures that the logic used to generate relative paths remains identical between local and production builds.
# _config.yml
url: "https://username.github.io"
baseurl: "/repository-name"
When running locally, use the --url flag to override the production domain while keeping the baseurl intact. This prevents divergent pathing for assets and internal links:
bundle exec jekyll serve --url "http://localhost:4000"
GitHub Pages utilizes a strict whitelist of supported plugins. If a plugin listed in your _config.yml is not on this whitelist, the GitHub Pages runtime silently ignores it. The build process will not fail or throw a critical error; however, any functionality, liquid tags, or filters provided by that plugin will be absent from the production site.
To verify plugin compatibility locally, you can use the jekyll-github-pages gem, which mimics the GitHub Pages environment and whitelist constraints.
jekyll -v locally to ensure you are on a 4.x release._site directory after a local build to confirm that baseurl is being prepended to assets as expected.Diagnostic Note: Please clarify if this is a User/Organization site (username.github.io) or a Project site (username.github.io/repo/), as User sites typically require an empty baseurl.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.