How to manage multiple configuration files for Octopress?

35 Views Asked by At

I have settings as below in _config.yml so that I can get tracking information with the help of GA.

# Google Analytics
google_analytics_tracking_id: UA-9118****-2

And this is how I deploy.

What I want to do is to have two different configurations based on the environments where it runs.

For example)

I hope the value of google_analytics_tracking_id on production is UA-AAAABBBB-1 and it is UA-AAAABBBB-2 on localhost.

Are there any approaches to do this without editing the _config.yml manually each time I deploy?

1

There are 1 best solutions below

0
David Jacquel On

You can use jekyll.environment variable that is set to "development" when you run jekyll locally with jekyll serve, and set to "production" on github pages.

_config.yml

google_analytics_tracking_id_dev: UA-9118****-1
google_analytics_tracking_id_prod: UA-9118****-2

In your code :

{% if jekyll.environment == 'production' %}
  {{ site.google_analytics_tracking_id_prod }}
{% else %}
  {{ site.google_analytics_tracking_id_dev }}
{% endif %}