如何确定jekyll是在本地还是在生产站点中运行? [英] How to detemine if jekyll running locally or in production site?

查看:44
本文介绍了如何确定jekyll是在本地还是在生产站点中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jekyll中有一个名为production_url的配置参数.我找不到有关如何使用它的任何信息.

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

理想情况下,我希望能够在使用serve参数运行时使用本地url生成永久链接,而在使用build参数运行时使用生产url生成永久链接.

Ideally i would like to be able to generate permalinks with local url when it is being run with serve param and with production url when run with build param.

我该怎么办?

推荐答案

jekyll serve将调用jekyll build,因此您不能真正使用这两者作为输出不同URL方案的方式.

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

我构建了一个Jekyll插件,该插件使用液体过滤器_config.yml中的一个用户定义变量称为mode.

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

您将mode设置为开发生产,该插件将处理模板中的其余部分.

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

因此,在您的模板中,您可以有一个URL,例如:

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

<img src="{{ '/img/dog.jpg' | to_absurl }}" />

mode开发时,在Jekyll构建/提供服务时,您将获得相对 URL:

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

<img src="/img/dog.jpg" />

在本地可以通过以下方式访问:http://0.0.0.0:4000/img/dog.jpg

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

mode生产时,在Jekyll构建/提供服务时,您将获得绝对 URL:

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

<img src="http://www.domain.tld/img/dog.jpg" />

http://www.domain.tld是您在_config.yml-> 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/

这篇关于如何确定jekyll是在本地还是在生产站点中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆