ozntel / oz-clear-unused-images-obsidian

Obsidian plugin to clear the images that are not used in note files anymore
194 stars 16 forks source link

Delete images in FrontMatter (Banners Plugin) #5

Closed javiavid closed 3 years ago

javiavid commented 3 years ago

I really like your plugin, it is very useful, but I have recently started using the Banners plugin (https://github.com/noatpad/obsidian-banners), which adds a local image in the FrontMatter. When I run your plugin, it does not detect that image belongs to that note and eliminates it.

Is an option possible so that this does not happen?

Thanks

ozntel commented 3 years ago

The plugin will now take into consideration the image links within all frontmatters. Kindly update from community plugins.

javiavid commented 3 years ago

Thank you!

gssantana commented 3 years ago

The plugin will now take into consideration the image links within all frontmatters. Kindly update from community plugins.

Is it possible consider images from into from code block? For example:

title: Test

![[Pasted image 20210912102534.png]]

Today, when I run "Clear Unused Images" those images are deleted.

ozntel commented 3 years ago

The plugin will now take into consideration the image links within all frontmatters. Kindly update from community plugins.

Is it possible consider images from into from code block? For example:

title: Test

![[Pasted image 20210912102534.png]]

Today, when I run "Clear Unused Images" those images are deleted.

Obsidian doesn't consider them as a link in case you include within the code block. The plugin basically scans all cached resolved links by Obsidian and compares with your local images. If any of local image doesn't have a reference in resolved links, it adds into the list of deletion. Obsidian also caches frontmatters, therefore, javiavid's request didn't require much rework.

However, to be able to detect the images within the code blocks, I would need to create a new scan method, which goes through all markdown files one by one, matches all Wiki and Markdown linked image links using regex. Then extract the name of file from the match with a new regex and find if this file name exists within the vault.

It is doable but requires a little bit time. But I might consider in the future when I have a while to write the code required. It would basically be another check just in case there is any other link, which is not included in the resolved links. Meanwhile, I would suggest referring the images, which are in code blocks, in a separate place to ensure they are referenced.