question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using with plugin that renames final files?

See original GitHub issue

I have a repo branch at https://github.com/brycewray/eleventy_solo/tree/base where, among other things, I’m attempting to use both this plugin and eleventy-plugin-local-respimg. Whenever I try to do a dev build, your plugin initially seems to work but, then, the console output becomes a long string of Error: ENOENT-type messages indicating the image files and/or their directories don’t exist. This doesn’t happen if I’m not using your plugin. Since the other plugin (like others that generate responsive images) renames the final files in the Eleventy output directory, is that related to this issue I’m experiencing? Note that I’m getting these error messages even on files I specifically exclude from that other plugin, specifically the files in /src/images/icons/.

Thanks in advance for any help and/or info you can provide; please let me know if you need additional details about the issue I’m experiencing.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
liamfiddlercommented, Jul 29, 2020

The newly released v2 of this plugin supports WEBP 🎉

In addition, the plugin will now automatically check for a ./src directory if the image cannot be found from the root directory, so you no longer have to pass a custom transformImgPath function. Hopefully in the future we can handle other directory structures too, once https://github.com/11ty/eleventy/issues/789 is resolved and we can compare the input and output paths.

2reactions
liamfiddlercommented, May 13, 2020

Hi Bryce! 👋

Thanks for providing the repo branch - it makes the discussion so much easier.

There’s two issues I’m aware of that might be impacting your project:

  1. There are two plugins reading from & modifying IMG tags.
  2. The source file path doesn’t start in the root directory.

Issue 1

I haven’t tried eleventy-plugin-local-respimg yet, but I’ve had success combining this plugin with eleventy-plugin-local-images which also moves and renames files. You can find a working example here.

The key to solving this problem was the order in which the plugins are defined in .eleventy.js. It was important lazyimages comes after local-images otherwise lazyimages would still be referencing the original filepath, not the modified one. I suspect a similar solution can be found for local-respimg.

Issue 2

This plugin assumes your file paths match the output paths, i.e. <img src="/images/dog.jpg" exists at <project root>/images/dog.jpg, but in your file structure it would be <project root>/src/images/dog.jpg.

This can be resolved using the transformImgPath config option. It allows you to specify a function that points the plugin to the internal image path.

Something like this might work for you (untested):

// .eleventy.js
eleventyConfig.addPlugin(lazyImagesPlugin, {
  transformImgPath: (imgPath) => {
    if (imgPath.startsWith('/') && !imgPath.startsWith('//')) {
      return `./src${imgPath}`;
    }

    return imgPath;
  },
});

TLDR;

Try reordering the plugins in .eleventy.js so local-respimg is before lazyimages.

Also try changing the lazyimages transformImgPath plugin config option to point to src or local-respimg’s output directory (maybe _site?).

I might have some time later this week, I’ll pull down your repo and take a look if the above doesn’t solve it 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugin to rename final datasets - Dataiku Community
Hello, Please, I need a plugin that renames all my final files of my project DSS stored in managed filesytem and put them...
Read more >
How to rename the final generated file in a Brunch plugin?
Exemple : In this config file i want to make a /js/master.js file. The goal of this plugin is to rename this filename...
Read more >
Phoenix Media Rename - Plugins - WordPress.org
The Phoenix Media Rename plugin allows you to easily rename (and retitle) your media files, once uploaded.
Read more >
How to Rename Images and Media Files in WordPress
In this article, we will show you how to easily rename images and media files in WordPress. We'll also show you a method...
Read more >
In plugins, renaming files as part of transformation #530 - GitHub
When writing plugins that transform files between completely different 'formats', it would be helpful to be able to rename the files as the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found