greenrivers / grav-plugin-webp

Grav Webp plugin.
MIT License
11 stars 0 forks source link

Unable to reach images using |webp #15

Open Fuficek opened 1 month ago

Fuficek commented 1 month ago

``I've tried using the webp plugin before and now I got stuck on the same issue. The images I want to display in webp are still jpgs. Even through I've converted them and they are saved in the folder webp in user. The functions '|webp' does not seem to work.

The following code displays the jpg version of the image image image

Any ideas why that might be?

All versions are up to date, cleared cache many times, and spent a week working on a workaround that kind of worked but is not in any way optimal.

{% set pageMedia = page.media.images %}
{% if pageMedia|length > 0 %}
    {% set firstImage = pageMedia|first %}
    {% if firstImage.url|split('.')|last == 'webp' %}
        {% set webp_url = firstImage.url %}
        {% set webp_exists = file_exists(webp_url) %}
    {% else %}
        {% set webp_url = firstImage.url|replace({'/user/pages/': '/user/webp/user/pages/'})|replace({'.jpg': '.webp', '.jpeg': '.webp', '.png': '.webp', '.JPG' : '.webp'}) %}
        {% set webp_filename = webp_url|split('/')|last %}
        {% set file_path_array = webp_url|split('/') %}
        {% set file_path_array = file_path_array|slice(0, -1) %}
        {% set webpFilePath = file_path_array|join('/')  %}
        {% set webp_exists = file_exists(webpFilePath ~ webp_filename) %}
    {% endif %}
    {% if file_exists(webpFilePath ~ webp_filename) %}
        <img class="l3-img effectscroll_3" src="{{ webp_url }}" alt="{{ firstImage.alt }}" />
    {% else %}
        <img class="l3-img effectscroll_3" src="{{ firstImage.url }}" alt="{{ firstImage.alt }}" />
    {% endif %}
{% endif %}

_this worked until the plugin fileexists stopped cooperating :(

MajorKuprich commented 3 weeks ago

Hello @Fuficek,

At the first make sure that You met the requirements from the docs: https://github.com/greenrivers/grav-plugin-webp#requirements

Did You clear cache after convert images?

Could You provide info about:

Regards