Is there a way to check whether a jekyll site is being served locally?

后端 未结 3 570
面向向阳花
面向向阳花 2021-01-06 00:51

I\'d like to add the following line to my head.html solely when running jekyll serve locally:

  

        
3条回答
  •  粉色の甜心
    2021-01-06 01:25

    When you do a jekyll serve locally the default {{ jekyll.environment }} variable is set to "development".

    You can then do a simple :

    {% if jekyll.environment == "development" %}
      
    {% endif %}
    

    If you want to run jekyll on another server, with another environment value, you can set a JEKYLL_ENV system environment variable to whatever you want.

    Setting this variable at runtime can be done like this :

    JEKYLL_ENV=production jekyll serve
    

    Note : On Github Pages, jekyll.environment is set to production.

提交回复
热议问题