How to detemine if jekyll running locally or in production site?

前端 未结 4 1764
谎友^
谎友^ 2021-02-13 03:25

There is a config param in jekyll called production_url. I can\'t find any information on how to use it.

Ideally i would like to be able to generate permalinks with loc

4条回答
  •  Happy的楠姐
    2021-02-13 04:24

    jekyll serve will call jekyll build, so you can't really use those two as a way to output different URL schemes.

    I built a Jekyll plugin that does this with a Liquid Filter and one user defined variable in your _config.yml called mode.

    You set the mode to development or production and the plugin takes care of the rest in your templates.

    So in your template you could have a URL such as:

    
    

    When mode is development, upon Jekyll build/serve you will get a relative URL:

    
    

    Locally this would be accessed as: http://0.0.0.0:4000/img/dog.jpg

    When mode is production, upon Jekyll build/serve you will get an absolute URL:

    
    

    The http://www.domain.tld is what you have set in _config.yml -> url variable.

    You can see more details on the plugin here:

    http://jhaurawachsman.com/2013/jekyll-url-helper-filter-plugin/

提交回复
热议问题