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

@elderjs/plugin-images - Deleting image from source folder not reflected in generated files #30

Closed
meigo opened this issue Oct 1, 2020 · 4 comments

Comments

@meigo
Copy link
Contributor

meigo commented Oct 1, 2020

Deleting (or renaming) image files from source folder doesn't remove related generated images and entries from ejs-image-manifest.json. Is this intended behaviour?

@meigo meigo changed the title @elderjs/plugin-images - Source folder update @elderjs/plugin-images - Deleting image from source folder not reflected in generated files Oct 1, 2020
@meigo
Copy link
Contributor Author

meigo commented Oct 3, 2020

Ok. As a result of fixing this issue github.com/Elderjs/plugins/issues/31 only the image sizes from plugin configuration will be copied over to public folder during the build, so it in principle fixes this issue as well.

Image cache itself is persistent and all the sizes once generated will stay there and this is probably for performance reasons.

Some notes:

Added these lines to .gitignore to keep cache files out of repository

/images/sizes/
/images/*.json

Cleaning cache

Added explicitly default cache related values to elder.config.js

imageManifest: '/images/ejs-image-manifest.json',
cacheFolder: '/images/sizes/',

and created package script to clear the cache when it feels appropriate

//src/cleanImageCache.js

const del = require('del');
const path = require('path');
const { getConfig } = require('@elderjs/elderjs');
a
const { rootDir, plugins } = getConfig();

console.log(' Clearing out image cache.');

if (plugins['elderjs-plugin-images'] !== undefined) {
  const plugin = plugins['@elderjs/plugin-images'];
  if (plugin.imageManifest !== undefined) {
    del.sync(path.join(rootDir, plugin.imageManifest));
  }
  if (plugin.cacheFolder !== undefined) {
    del.sync(path.join(rootDir, plugin.cacheFolder));
  }
}
node ./src/cleanImageCache.js

@nickreese
Copy link
Contributor

@meigo We should add a check that update the manifest but for now, just delete it and the plugin will rebuild it without recreating the images.

I've added your scripts above to the readme.

@meigo
Copy link
Contributor Author

meigo commented Oct 4, 2020

Thanks.
Small mistake in script above, sorry about this, should be

//src/cleanImageCache.js

const del = require('del');
const path = require('path');
const { getConfig } = require('@elderjs/elderjs');

const { rootDir, plugins } = getConfig();

console.log(' Clearing out image cache.');

if (plugins['@elderjs/plugin-images'] !== undefined) {
  const plugin = plugins['@elderjs/plugin-images'];
  if (plugin.imageManifest !== undefined) {
    del.sync(path.join(rootDir, plugin.imageManifest));
  }
  if (plugin.cacheFolder !== undefined) {
    del.sync(path.join(rootDir, plugin.cacheFolder));
  }
}

@nickreese
Copy link
Contributor

@meigo Thanks!

@meigo meigo closed this as completed Oct 7, 2020
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