Delete a page and also delete its assets

After I delete a page, the images from the deleted page is still in my assets folder.

Would be handy to have a feature that deletes the assets attached to that page. Provided its not linked to another page.

+1 to this feature request.
It would be great if logseq can detect orphan assets and ask the users if they want to delete them.

1 Like

Just as a workaround, here’s how I am doing it (I started only a month ago with logseq, so forgive me if this is wrong or dangerous. Backup your graph before playing with this).

I have a findOrphan.sh script in my graph root

#!/bin/bash


grep -R $1 ./journals ./pages > /dev/null || echo orphan: $1

From my graph root I do

find assets -type f -exec ./findOrphan.sh $(basename {}) \;

Which prints a list of orphaned assets. You could theoretically replace the echo with a rm to have this acting as a garbage collector.

Note that this does not look into the logseg/bak directory but depending on your syncing strategy (I use syncthing) a conflict file might keep a reference to an asset. I chose not to exclude conflict files from the find, as that’s a matter of preference and this is a proof of concept (maybe naive)

1 Like

Or as a one-liner

find assets -type f -exec /bin/bash -c 'grep -R "{}" ./journals ./pages > /dev/null || echo orphan: "{}"' \;