Skip to content

Site generation duplicates baseurl for img when baseurl not empty #2639

@dolfs

Description

@dolfs

Checklist

How did you create the site?

Generated from chirpy-starter

Describe the bug

The problem manifest itself when baseurl in the _config.yml is defined as something other than empty.
This problem affects all markdown where an <img> tag is generated. Whatever the src attributed contains, it gets the baseurl prepended twice.

This seems to happen because a final step in rendering is to pull things through the refactoring code. For <img> tags, this then results in the subsequent code in refactoring ultimately calling

{% include media-url src=<baseurl>/assets/images/Flag.png> %}

This shows that the baseurl was already applied before it got to this point. The include prepends it again.

Steps To Reproduce

  1. Define baseurl as "my_site" in _config.yml
  2. In any .md file include (thec second variation to show this problem has nothing to do with the jekyll_picture_tag plugin):
Picture plugin: {% picture "Flag.png" --alt Flag %}

MD Image full path: ![Test]({% link /assets/images/Flag.png %})
  1. Observe output (formatted for clarity):
<p>
	Picture plugin:
	<picture>
		<source srcset="/my_site/assets/images_gen/Flag-400-dd43f229f.webp 400w, /my_site/assets/images_gen/Flag-600-dd43f229f.webp 600w, /my_site/assets/images_gen/Flag-800-dd43f229f.webp 800w, /my_site/assets/images_gen/Flag-1000-dd43f229f.webp 1000w, /my_site/assets/images_gen/Flag-1600-dd43f229f.webp 1600w" type="image/webp" />
		<source srcset="/my_site/assets/images_gen/Flag-400-a5c1e79ca.png 400w, /my_site/assets/images_gen/Flag-600-a5c1e79ca.png 600w, /my_site/assets/images_gen/Flag-800-a5c1e79ca.png 800w, /my_site/assets/images_gen/Flag-1000-a5c1e79ca.png 1000w, /my_site/assets/images_gen/Flag-1600-a5c1e79ca.png 1600w" type="image/png" />
		<a href="/my_site/my_site/assets/images_gen/Flag-800-a5c1e79ca.png" class="popup img-link shimmer">
			<img src="/my_site/my_site/assets/images_gen/Flag-800-a5c1e79ca.png" alt="Flag" loading="lazy">
		</a>
		</picture> 
</p>
<p>
	MD Image full path:
	<a href="/my_site/my_site/assets/images/Flag.png" class="popup img-link shimmer">
		<img src="/my_site/my_site/assets/images/Flag.png" alt="Test" loading="lazy">
	</a> 
</p>
  1. Notice that in both cases the <img> tag was surrounded by an <a> during refactoring (fine), and the src attribute in the tag now has the baseurl value in there twice. Tags like <source> which also contain image paths are unaffected by the refactoring code, and consequently are correct.

Expected Behavior

Do not double up on the baseurl

Environment

  • Ruby:
  • Jekyll:
  • Chirpy:

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions