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

Script deletes used images if file extensions are capitals e.g. .JPG #7

Closed
claremacrae opened this issue Oct 21, 2021 · 5 comments
Closed

Comments

@claremacrae
Copy link

claremacrae commented Oct 21, 2021

This plugin deletes images that are linked.

I was able to restore them from version control, so I'm OK... but still...

Environment

  • macOS 10.15.7
  • Obsidian v0.12.19
  • Clear Unused Images 1.0.3

Demonstration

Here are some existing links to images:

%% Zoottelkeeper: Beginning of the autogenerated index file list  %%
📄 [[Clare/Humour and interesting things/IMG_0439 - Quantum Engagement - Jim Al-Khalili.PNG|IMG_0439 - Quantum Engagement - Jim Al-Khalili.PNG]]
📄 [[Clare/Humour and interesting things/IMG_0441 - Traditionalist Cartoon.JPG|IMG_0441 - Traditionalist Cartoon.JPG]]
📄 [[Clare/Humour and interesting things/IMG_0591 - Sufficiently Advanced Stupidity.PNG|IMG_0591 - Sufficiently Advanced Stupidity.PNG]]
📄 [[Clare/Humour and interesting things/IMG_0625 - REDACTED.PNG|IMG_0625 - REDACTED.PNG]]
📄 [[Clare/Humour and interesting things/IMG_2030 - Blame the Straight People.JPG|IMG_2030 - Blame the Straight People.JPG]]
%% Zoottelkeeper: End of the autogenerated index file list  %%
# Amusing Images

![[IMG_0439 - Quantum Engagement - Jim Al-Khalili.PNG]]

![[IMG_0441 - Traditionalist Cartoon.JPG]]

![[IMG_0591 - Sufficiently Advanced Stupidity.PNG]]

![[IMG_0625 - REDACTED.PNG]]

![[IMG_2030 - Blame the Straight People.JPG]]

When I run "Clear unused images" I get this output, showing me that all those linked images were deleted:

image

@lishid
Copy link

lishid commented Nov 2, 2021

Seems to be caused by this RegExp not matching case insensitively (and your images are .JPG instead of .jpg)

const imageRegex = /.*(jpe?g|png|gif|svg|bmp)/;

@claremacrae
Copy link
Author

claremacrae commented Nov 2, 2021

Thanks!

I'm not sure... I'm experimenting with it some more - I just tried it out with this:

![[20211102074439.PNG]]

[[20211102074454.PNG]]

Where the images are .png - and got "no files deleted"

(I am on a Mac, where the filesystem is case-insensitive)

@claremacrae
Copy link
Author

Seems to be caused by this RegExp not matching case insensitively (and your images are .JPG instead of .jpg)

const imageRegex = /.*(jpe?g|png|gif|svg|bmp)/;

Confirmed.... If the case of the file extension is not all-lower on disc, then the files are removed - even if they are used, and used with consistent extensions in the markdown.

Thank you for working out the cause...

@claremacrae claremacrae changed the title Deletes images that are used!!! Script deletes used images if file extensions are captils e.g. .JPG Nov 2, 2021
@claremacrae claremacrae changed the title Script deletes used images if file extensions are captils e.g. .JPG Script deletes used images if file extensions are capitals e.g. .JPG Nov 2, 2021
ozntel pushed a commit that referenced this issue Nov 2, 2021
@ozntel
Copy link
Owner

ozntel commented Nov 2, 2021

I just released a version, in which the check for image extension is not case sensitive.
@claremacrae Let me know if the issue still persists.
Thanks!

@ozntel ozntel closed this as completed Nov 2, 2021
@claremacrae
Copy link
Author

Thanks very much! And thanks to @lishid for spotting the cause...

I've done the following tests - all successful: 🎉

  1. Checked that it no longer deletes used .PNG and other capitalised extensions
  2. Checked that it does delete unused .PNG files

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

3 participants