Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: shortcode images don't load after build #37

Merged
merged 1 commit into from
May 16, 2023

Conversation

goingforbrooke
Copy link
Contributor

Issue

This fixes an issue where images added with the image shortcode are visible via zola serve but not zola build.

Solution

It works by prepending the site's base URL to external image URLs so https://www.awesomesite.com/flower.png is just as valid as http://127.0.0.1:1111/flower.png.

External images are differentiated from internal images by the presence of http at the beginning of their URL.

Fixes issue #36.

This fixes an issue where images added with the [`image` shortcode](https://github.com/pawroman/zola-theme-terminimal#image) are visible via `zola serve` but not `zola build`.

It works by [prepending](https://tera.netlify.app/docs#concatenation) the site's base URL to external image URLs so `https://www.awesomesite.com/flower.png` is just as valid as `http://127.0.0.1:1111/flower.png`.

External images are differentiated from internal images by the presence of `http` at the beginning of their URL.

Fixes issue pawroman#36.
goingforbrooke added a commit to goingforbrooke/personal_blog that referenced this pull request May 11, 2023
This works by prepending the site's `base_url` to internal
image paths. Image URLs are deemed to be external if they
begin with `http`.

This fix was added to a PR for the Terminimal theme.

PR: pawroman/zola-theme-terminimal#37
@pawroman
Copy link
Owner

Thanks for the fix!

@goingforbrooke
Copy link
Contributor Author

My pleasure. Thanks for an awesome theme! :)

@ipetkov
Copy link
Contributor

ipetkov commented Jun 4, 2023

Came across this while updating my site, turns out this change actually breaks relative image URLs 😬

Basically I am using {{ image(src="blah.jpg") }} since sometimes I organize posts in their own directory (where index.md and the photo are siblings under the same directory). Browsers will interpret the URL as being relative to the current URL, except now the URL is rewritten to http://127.0.0.1:1111/flower.png even though the actual image is located at http://127.0.0.1:1111/the_post/flower.png

@pawroman
Copy link
Owner

pawroman commented Jun 5, 2023

Sorry to hear that @ipetkov and thanks for reporting. I have created an issue to track this. Will look into it in my spare time (which might actually take a while 😅 )

@goingforbrooke
Copy link
Contributor Author

Sorry @ipetkov! I'll look at this later today @pawroman.

@ipetkov
Copy link
Contributor

ipetkov commented Jun 5, 2023

No worries and no rush on this y'all! I have my commit pinned so my site isn't actually "broken" atm, just wanted to note the behavior change! 😄

Happy to follow the issue until it's addressed

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.

3 participants