Skip to content

Instantly share code, notes, and snippets.

@livoffgrid
Last active February 12, 2019 02:21
Show Gist options
  • Select an option

  • Save livoffgrid/3073bad55f951e03527f8bfae78dcef0 to your computer and use it in GitHub Desktop.

Select an option

Save livoffgrid/3073bad55f951e03527f8bfae78dcef0 to your computer and use it in GitHub Desktop.

local/prod config swap for jekyll on github pages

Freely hosted sites with github pages are super handy, but not being able to manage environment specific configs is a PITA.

Here is my little hack for keeping my localhost configs separate from the production ones that get pushed up to github. I'm only using this for oauth client_ids (which are visible in the browser anyway - don't check in anything that truly needs to be kept secret!). With oauth client_ids it's pretty common to have one scoped for localhost and another scoped for your production domain, the case we're solving for here is keeping that localhost scoped id a secret.

Basically:

  • make a file similar to make_local_config.sh
  • make it executable chmod 755 make_local_config.sh
  • add make_local_config.sh and _local_config.yml to your .gitignore
  • edit your make_local_config.sh to contain the keys you want to replace in _config.yml

Then when you want to run jekyll locally, start it like this:

./make_local_config.sh && be jekyll serve --config=_local_config.yml
#!/bin/bash
cp _config.yml _local_config.yml
sed -i "" -e "s/PROD_CONFIG_VALUE/LOCAL_CONFIG_VALUE/g" _local_config.yml
# -i changes the file in-place
# osx is janky and if you use just `-i` without the empty quote it will fail, more here: https://stackoverflow.com/a/19457213
# If you have many values to replace consider putting them in a separate file and iterating over the items instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment