如何将 `url` 站点变量设置为 `jekyll serve --host …` 中指定的主机和端口?

How to set the `url` site variable to host and port specified in `jekyll serve --host …`?

如何从 jekyll 插件左右访问 jekyll serve 运行 站点所在的主机和端口,以从正确的位置加载带有绝对链接的资产?

当我 运行 jekyll serve --host example.local --port 1234 我想将 url 变量(在 _config.yml 中设置为 example.com)更改为给定的主机和端口所以我可以使用 {{ site.url }}/css/site.css 而无需获得我的生产资产。当没有指定其他内容时,获得默认值 localhost:4000 也很好。

如果你想获得完整的 url 端口,你可以这样做:

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

默认情况下 {{ fullUrlWithPort }} 会给你 http://127.0.0.1:4000

如果你启动一个 jekyll serve --host myhost --port 1234 它会给你一个 http://myhost:1234