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

Remote images not being optimised #22

Closed
ItsEthanH opened this issue Oct 22, 2023 · 2 comments
Closed

Remote images not being optimised #22

ItsEthanH opened this issue Oct 22, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ItsEthanH
Copy link

Hello :)

I think I've uncovered a bug whereby using images via https doesn't result in images being fetched, optimised and rendered in tags.

My config is as follows:

./src/config/plugins/image.js

module.exports = {
	eleventyInputDir: "./src",
	imagesOutputDir: "public/assets/images",
	urlPath: "/assets/images/",
	fetchRemote: true,
	minWidth: 50,
	maxWidth: 2000,
	hoistImgClass: true,
	widthStep: 200,
	sizes: "100vw",
	sharpAvifOptions: {
		quality: 95,
	},
	sharpWebpOptions: {
		quality: 95,
	},
	sharpJpegOptions: {
		quality: 95,
	},
};

I'm then using eleventy with a Shopify plugin to fetch images and render them in the form of cards, using a Nunjucks macro. I have tested this using just an image tag, and the same still applies. The macro is called like so:

pages/product-listing.html

{% from 'components/listed-product.html' import listedProduct %}
...
  <section class="plp-listing">
    <ul class="plp-listing__container">
      {% for product in shopify.products | reverse %}
        {{ listedProduct(
          product.images.nodes[0].src,
          product.title,
          "$" + product.variants.nodes[0].priceV2.amount | formatPrice,
          '',
          "/products/" + product.handle)
        }}
      {% endfor %}
    </ul>
  </section>

Then this listed-product macro is as follows

_includes/components/listed-product.html

{% macro listedProduct(src, name, price, styles, href) %}
  <li class="listed-product {{ styles }}">
    <img class="listed-product__image" src="{{ src }}" alt="{{ name }}">
    <p class="listed-product__title">{{ name }}</p>
    <p class="listed-product__price">
      {{ price }}
    </p>
    <a href="{{ href }}" class="listed-product__button">View Product</a>
  </li>
{% endmacro %}

Finally, the built HTML in /public is so:

  <li class="listed-product ">
    <img class="listed-product__image" src="https://cdn.shopify.com/s/files/1/0748/0872/1690/files/edit-9.jpg?v=1689013081" alt="Proverbs Woman">
    <p class="listed-product__title">Proverbs Woman</p>
    <p class="listed-product__price">
      $55.00
    </p>
    <a href="/products/proverbs-woman" class="listed-product__button">View Product</a>
  </li>

Let me know if you need anything further from me :)

@saneef
Copy link
Owner

saneef commented Oct 22, 2023

Thanks @ItsEthanH pointing this out. I'll look into it.

saneef added a commit that referenced this issue Oct 22, 2023
@saneef saneef added the bug Something isn't working label Oct 22, 2023
@saneef saneef self-assigned this Oct 22, 2023
@saneef saneef closed this as completed in bf13fc4 Oct 22, 2023
@saneef
Copy link
Owner

saneef commented Oct 22, 2023

I have published a new version 4.1.3. This issue should be resolved. Do reopen this issue if it doesn't.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants