如何将"url"站点变量设置为"jekyll serve --host…"中指定的主机和端口? [英] How to set the `url` site variable to host and port specified in `jekyll serve --host …`?

查看:156
本文介绍了如何将"url"站点变量设置为"jekyll serve --host…"中指定的主机和端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从jekyll插件内部访问运行jekyll serve网站的主机和端口,以便从正确的位置加载绝对链接的资产?

How can I access the host and port that jekyll serve runs the site on from inside a jekyll plugin or so, to load my assets with absolute links from the right place?

当我运行jekyll serve --host example.local --port 1234时,我想将url var(在_config.yml中设置为example.com)更改为给定的主机和端口,以便我可以使用{{ site.url }}/css/site.css而无需获取我的生产资产.另外,如果未指定其他任何内容,最好使用默认的localhost:4000.

When I run jekyll serve --host example.local --port 1234 I want to change the url var (set to example.com in _config.yml) to the given host and port so that I can use {{ site.url }}/css/site.css without getting my production assets. Also it would be nice to get the default localhost:4000 when nothing else is specified.

推荐答案

如果要获取带有端口的完整URL,可以执行以下操作:

If you want to get the full url with port, you can do :

{% assign fullUrlWithPort = site.host | prepend:"http://" | append:":" | append: site.port %}

默认情况下,{{ fullUrlWithPort }}将为您提供http://127.0.0.1:4000.

By default {{ fullUrlWithPort }} will give you http://127.0.0.1:4000.

如果启动jekyll serve --host myhost --port 1234,它将为您提供http://myhost:1234

If you launch a jekyll serve --host myhost --port 1234 it will give you a http://myhost:1234

这篇关于如何将"url"站点变量设置为"jekyll serve --host…"中指定的主机和端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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