2

can anyone help me figure out why site.url does NOT change to http://localhost:4000 per the documentation? It mirrors the url param in _config.yml. I have checked and jekyll.environment = development.

I have spun up a new Jekyll project on a different machine and the results are the same.

2 Answers2

2

This feature has been disabled in version 4.2.0. What a waste of time this has been.

Here's a workaround.

0

That documentation does mention:

It will not be set if you set JEKYLL_ENV=production and run jekyll serve.

If JEKYLL_ENV is any value except development (its default value), Jekyll will not overwrite the value of URL in your config.
And again, this only applies to serving, not to building.

So double-check your JEKYLL_ENV value, and your command (jekyll serve)

The OP points out to jekyll/jekyll PR 7253 in jekyll v4.2.0

Local tests show that the local preview server is based on config["host"] and config["port"] values.. So even if config["url"] == https://jekyllrb.com, the site will be served at the default setting: //127.0.0.1:4000

This simplifies users' workflow by not having to build the site again with JEKYLL_ENV=production
(unless their templates are designed to render differently for the two ENV vars, which is a different story altogether)

This, however, is in the process of being reverted: PR 8620

The documentation on jekyllrb.org was not updated to reflect this change in behavior,

That change did not affect cases where the local server URL was explicitly set via bundle exec jekyll serve --host localhost --port 4000 to be localhost:4000, or when it was set to be any other combination of hosts or ports.

That change only affected the default jekyll serve, which is the local development action recommended in the Jekyll docs.

So this could be a workaround in your case:

bundle exec jekyll serve --host localhost --port 4000
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I mentioned in my post that the `jekyll.environment` variable is set to `development`. I don't know how else to test this since the documentation does not specify what kind of variable `JEKYLL_ENV` is. Is it an environment variable? A site variable? Either way, I think it's set correctly. – user16270045 Jun 20 '21 at 02:23
  • @user16270045 Exactly: en environment variable. Type `env` on Linux or `set` on Windows, to check if that environment variable is set. – VonC Jun 20 '21 at 02:35
  • I appreciate your feedback. I've set the variable and the results are the same. I'm sure it's' the correct variable, because I can see the results when I output `{{site.url}}`. I'm still getting the _config.yml settings and not `http://localhost:4000/`. – user16270045 Jun 20 '21 at 17:09
  • @user16270045 What OS and OS version are you using? What shell version? And are you typing `jekyll serve` in the same CMD/shell where you see the environment variable `JEKYLL_ENV` set to `development`? (What version of `jekyll` are you using?) – VonC Jun 20 '21 at 17:25
  • @user16270045 Does a python (3) serve works, as in https://stackoverflow.com/a/59392477/6309? – VonC Jun 20 '21 at 17:26
  • See my reply. The feature has been disabled in version 4.2.0. Thanks for the help. – user16270045 Jun 20 '21 at 17:28