Skip to content

Conversation

@dolfs
Copy link

@dolfs dolfs commented Jan 23, 2026

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Description

When baseurl in _config.yml is not empty, without this fix, it can be prepended more than once, which is incorrect.

This fix adds logic to prevent prepending the baseurl when it is already a prefix in the url, but correctly handles cases where it is a prefix, but the url does not follow this prefix with a path/url separator.

For example, when baseurl is set to /blog, but the url starts with /blogger it is not considered "prefixed" and /blog/ is prepended (resulting in /blog/blogger…, but if the url starts with /blog/it is considered "prefixed" and is not prepended again (keeping/resulting in/blog/…`)

A limitation is that if the user supplied a (partial) URL starting with /blog/ and truly intended to produce /blog/blog/, it won't work.

Additional context

Fixes #2639, and:

  • Prevents occasional introduction of white space
  • Check for pre-existing absolute url is made more robust
  • Better handling of scenarios where site.baseurl ends in '/', or accidentally was set to just '/'

@dolfs dolfs force-pushed the media-url-logic-fix branch from 2b72783 to a830fe2 Compare January 23, 2026 05:37
When baseurl in _config.yml is not empty, without this fix, it can be prepended more than once, which is incorrect.

This fix adds logic to prevent prepending the baseurl when it is already a prefix in the url, but correctly handles cases where it is a prefix, but the url does not follow this prefix with a path/url separator.

For example, when baseurl is set to /blog, but the url starts with /blogger it is not considered "prefixed" and /blog/ is prepended (resulting in /blog/blogger…, but if the url starts with /blog/it is considered "prefixed" and is not prepended again (keeping/resulting in/blog/…`)

A limitation is that if the user supplied a (partial) URL starting with /blog/ and truly intended to produce /blog/blog/, it won't work.

Fixes: cotes2020#2639
Signed-off-by: Dolf Starreveld <[email protected]>
@dolfs dolfs force-pushed the media-url-logic-fix branch from a830fe2 to d9de8d4 Compare January 23, 2026 05:39
dolfs added a commit to dolfs/jekyll-theme-chirpy that referenced this pull request Jan 23, 2026
…riately

Both home and post layouts did some of the work already done by _include/media-url.html. Since that _include was fixed to deal with the double prepend of baseurl, these layouts still had the problem.

Change that so they use the include. Only effective when the previous PR is also merged.

depends-on: PR cotes2020#2648
Signed-off-by: Dolf Starreveld <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site generation duplicates baseurl for img when baseurl not empty

1 participant