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: Use resize_image Built-in Function to Generate Image URLs #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions templates/shortcodes/image.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% if src %}
{# If the image's URL is internal to the site... #}
{% if src is not starting_with("http") %}
{# ... then prepend the site's base URL to the image's URL. #}
{% set src = config.base_url ~ src %}
{# ... then convert the page's colocated_path attribute to a string so it can be concatenated... #}
{% set colocated_path = page.colocated_path | as_str %}
{# ... and use `resize_image` to get image's URL for colocated blog posts and non-colocated blog posts. #}
{% set image = resize_image(path=colocated_path ~ src, width=5000, height=5000, op="fit") %}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're setting the image variable which is a compound object.

Suggested change
{% set image = resize_image(path=colocated_path ~ src, width=5000, height=5000, op="fit") %}
{% set image = resize_image(path=colocated_path ~ src, width=5000, height=5000, op="fit") %}
{% set src = image.url %}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, unrelated to the above: I hope that this resizing won't decimate the image quality (e.g. in JPEG case, we'd really want to avoid re-encoding).

Can you confirm it's not going to re-encode JPEGs needlessly?

{% endif %}
<img src="{{ src | safe }}"{% if alt %} alt="{{ alt }}"{% endif %} class="{% if position %}{{ position }}{% else -%} center {%- endif %}" {%- if style %} style="{{ style | safe }}" {%- endif %} decoding="async" loading="lazy"/>
{% endif %}