Production builds

Some plugins or includes blocks will behave differently when using production mode - locally or through GH Pages.

How to enable production mode

GitHub Pages will set a production value for you by default when it builds.

If you are running CI (GitHub Actions or Netlify) or want to do production build locally, run this:

JEKYLL_ENV=production bundle exec jekyll build

Or you can set your CI build’s environment variables as:

JEKYLL_ENV=production

Domain

When in production mode, Jekyll will use your configured URL value for absolute URLs, rather than the local dev value of http://localhost:4000/my-repo.

Sample config for this site.

url: https://michaelcurrin.github.io
baseurl: /dev-cheatsheets

This production mode and URL set up won’t affect links which use the relative_url

But _will/ affect links using absolute_url filter.

Notably, where that filter is used for files generated by you or plugins around SEO and feeds must have absolute URLs or they will not be read properly.

Some sample filenames with links:

Google Analytics

Here is a typical example of reading the variable and rendering conditionally. This ensures that analytics tracking only sends tracking data to your Google Analytics account for your production site. Thereby excluding activity on local dev or remote testing environments which is not real user activity but just people testing and not behaving like a typical browsing user.

{% if jekyll.environment == 'production' and site.google_analytics and site.google_analytics != '' %}
    {% include google-analytics.html %}
{% endif %}

GitHub metadata

When using the GitHub Metadata plugin to get data for your GH profile and repos, you will this error when doing a prod build locally, outside of GH Pages. Even if your remote is set, which is what is requests:

Liquid Exception: No repo name found. Specify using PAGES_REPO_NWO environment variables, 'repository' in your configuration, or set up an 'origin' git remote pointing to your github.com repository.

You can solve this by setting your “NWO” (name with owner) in your config file.

repository: username/repo-name

See Configuration help page for the GH Metadata plugin.