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

1

1

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?

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.

Membranous answered 9/9, 2015 at 19:39 Comment(0)
Y
1

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

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

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

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

Yoghurt answered 9/9, 2015 at 21:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.