Is there a way to check if the jekyll site is served locally?

I would like to add the following line to mine head.htmlonly when running jekyll servelocally:

  <script src="http://127.0.0.1:35729/livereload.js?snipver=1"></script>

I am thinking of using a simple fluid test, if possible.

+4
source share
2 answers

An alternative solution (for example, if you host the Jekyll website on your own server, and not on GitHub pages):

You can set the value in the configuration file _config.ymlas follows:

environment: prod

Then you may have another configuration file that overrides the same value, I will name it config_dev.yml:

environment: dev

When you just call jekyll build, it will use the value prodfrom the real configuration file.

, :

jekyll build --config _config.yml,_config_dev.yml

, environment dev.

, :

{% if site.environment == "dev" %}
  <script src="http://127.0.0.1:35729/livereload.js?snipver=1"></script>
{% endif %}

:

+8

jekyll serve {{ jekyll.environment }} "development".

:

{% if jekyll.environment == "development" %}
  <script src="http://127.0.0.1:35729/livereload.js?snipver=1"></script>
{% endif %}

jekyll , environment, JEKYLL_ENV

.

:

JEKYLL_ENV=production jekyll serve

. Github jekyll.environment production.

+7

All Articles