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

Local images #6

Closed
nothingrandom opened this issue Mar 16, 2020 · 4 comments
Closed

Local images #6

nothingrandom opened this issue Mar 16, 2020 · 4 comments

Comments

@nothingrandom
Copy link
Contributor

nothingrandom commented Mar 16, 2020

Can't get this to work with images as part of the build process. I think there's some path issues.
See that none of your examples allow for this - is that intentional?

@liamfiddler
Copy link
Owner

liamfiddler commented Mar 16, 2020

Hi @nothingrandom 👋

Images should be working - both locally and when pulled from a third-party server. To demonstrate this I've added some local images to the "basic" example.

Take a look at this commit to see what's changed.

Let me know if this example helps, or if you have a public repo I could look at 😃

@nothingrandom
Copy link
Contributor Author

Hey!
Thanks for the quick reply :) It does help somewhat, I think I now see the issue.

I think one of the big differences might be the project structure. My structure is like this;

.
├── .editorconfig
├── .eleventy.js
├── .eslintrc.js
├── .git/
├── .gitignore
├── .lightserverrc
├── .npmrc
├── .nvmrc
├── .snyk
├── .travis.yml
├── .typo-ci.yml
├── README.md
├── _redirects
├── dist/
├── netlify.toml
├── node_modules/
├── package.json
├── postcss.config.js
├── src/
│   ├── _data/
│   ├── _includes/
│   ├── browserconfig.xml
│   ├── css/
│   ├── favicon.ico
│   ├── fonts/
│   ├── img/
│   ├── js/
│   ├── pages/
│   └── site.webmanifest.njk
├── utils/
│   ├── filters.js
│   └── shortcodes.js
├── webpack.config.js
├── yarn-error.log
└── yarn.lock

So .eleventy.js is in the root, files and images are both in src/, and the project is building into the dist/

Should I do something to fix this my end, or does this want to be a plugin change, with some more support for folder structure?

@liamfiddler
Copy link
Owner

OK, I think I understand now.

The transformImgPath configuration option might help. 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
module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(lazyImagesPlugin, {
    transformImgPath: (imgPath) => {
      if (imgPath.startsWith('/') && !imgPath.startsWith('//')) {
        return `./src${imgPath}`;
      }

      return imgPath;
    },
  });

@nothingrandom
Copy link
Contributor Author

Yep, that worked perfect. Thank you very much!

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

No branches or pull requests

2 participants