Set up an environment to preview your github-pages locally
Unlike the half-baked guide on official docs, this repository provides a "setup once, use anywhere" environment for previewing github pages locally.
The generated preview closely matches GitHub's deployment runner, with negligible differences in a few {{ site.github }} properties. All page themes and plugins listed in github pages dependencies come bundled with the initial setup. This includes QoL plugins such as jekyll-github-metadata, jekyll-optional-front-matter, etc.
While most plugins in the said list are loaded by default on github pages, some need to be explicitly enabled via the plugins: list in _config.yml.
- Make sure
ruby,gemandbundlerare installedsudo apt install ruby ruby-dev build-essential
(or download from ruby-lang.org)gem install bundler
- Clone this repo, then run bundler to install dependencies locally
bundle install
- Optional: Copy
example.envto.envand edit the values. This step deals with repo naming and github API callscp example.env .env
To start the local server, run jekyll with --source flag with directory path of the repo you want to preview:
bundler exec jekyll serve --livereload --source ../your/repo/pathOr use runserver.sh which is a simple wrapper around that long command:
./runserver.sh ../your/repo/pathThe path defaults to the current directory if not specified.
Important
For resolving the repo name and github metadata variables, .env needs to be configured as mentioned in step 3 of the setup.
NEVER commit your API tokens to the public!
To update to the latest Github Pages version, run bundler's update command:
bundler update github-pagesFor further information or troubleshooting, refer to the documentation on Github Pages gem.