Base_path is production path during jekyll serve after update from 4.0.1 to 4.2.0

Hi

so I use Jekyll for walletscrutiny com and tried to upgrade Jekyll as I had issues with sorting. | reverse had no effect on the sorting.

I changed Gemfile line gem "jekyll", "~> 4.0.0" to gem "jekyll", "~> 4.2.0" and ran bundle update.

Before, running bundle exec jekyll serve --trace generated the page for localhost but now all the urls are using the production base_path. What happened between 4.0.1 and 4.2.0 and how do I fix this?

Since you have a custom domain, can you confirm that instead of base_path you actually mean url?

e.g.

url: https://example.com

And not baseurl. Which is probably left out or as empty string in your config.


Check out release notes

In particular 4.2

Additionally, we have stopped overriding the site.url to http://localhost:4000 in absolute URLs while developing via jekyll serve .

Can I suggest you convert most of your absolute URLs to relative URLs and see if that solves your problem? That should actually be good way to design Jekyll sites - I see a lot of people using absolute URLs unnecessarily. See my notes below.


I have a project running on 4.2, which has a custom URL in _config.yml. The change in Jekyll has not caused any breaks for me.

When I run jekyll serve I get:

    Server address: http://127.0.0.1:4000

And relative URLs work as before e.g. {{ '/' | relative_url }} renders as / (excluding domain).

I think the change you are noticing is that any use of absolute URLs uses the configured URL and not localhost (even when JEKYLL_ENV=production is not set).

For example, if I do this:

{{ '/' | absolute_url}}

I get this:

https://example.com

I am guessing that this behavior is breaking your local dev experience, but only where you are using absolute URL. Some easy code changes can fix this. My recommendation is to use relative URLs throughout your site.

i.e. Do this

[Bar]({{ '/foo/bar.html' | relative_url }}

And actually it is more robust to use link as below, because it will give you a desirable error at build time if the link is broken instead of failing quietly.

[Bar]({% link foo/bar.md %}

And that will give you a relative URL by the way (no domain). It is also great to use for assets e.g. {% link assets/js/main.js %}.

And only use absolute URLs for things which need to be absolute. Like sitemap values, robots.txt values and metadata tags in your head tag. If you use plugins so handle those like the SEO and sitemap plugins, you won’t even have to use absolute_url anywhere in your own project code.

If you get stuck with sorting, have a look at older forum posts or a open a new topic and @ mention and I’ll check it out.

Thank you Michael. Your comments made me look into the right spot. I was using AcademicPages (don’t ask why. That’s how I found Jekyll) and there was an _includes/base_path:

{% if site.url %}
  {% assign base_path = site.url | append: site.baseurl %}
{% else %}
  {% assign base_path = site.github.url %}
{% endif %}

and that include was used everywhere. I now changed the content to {% assign base_path = site.baseurl %} which appears to fix the issue.

1 Like

So it turns out that most issues are fixed now but redirects still link to the production site. I grep site.url over my whole repo and don’t see any relevant site.url anymore. The rest is all not me.

Okay that’s good to hear.

I don’t know that theme or how Jekyll redirects work.