Files can be used in blocks, in files fields, in textarea fields or simply directly in the template. While you could go through all content files and their field to look for references to a file, you would also have to keep track about those used directly in a template/snippet (unless you never do that).
As for the list of files itself, it would probably make sense to show them in a custom Panel area with an action to remove them.
I didn’t try any approach to it but for existing files, I would probably have tried to convert the whole index collection to JSON, then to one big string, then search for the ID/or URL in that structure, and then, as I would know that there are only a few patterns of data structures used, travel up the tree and find the page ID. That’s most likely resource hungry, but not as resource hungry as looping directly over the whole collection and its children. It would work, but probably ends in hardly maintainable code with many magic strings.
And then, to not have to do that all the time as the file library grows, try to save reference information down via hooks when a file is uploaded or a page is saved. That would give me one big file with all references that should be up-to-date as long as the panel is used for content management.
As I never use files uploaded to Kirby directly in snippets, that one wouldn’t be a problem.
Ah, that’s a great idea. I have to look into that.
Oh, I maybe interpret that differently too. I thought of static references to files uploaded to the CMS.
Looking at your example, I sure have these cases. However, thinking about it, I hardly have anything that is not transparent enough in the CMS to understand these. Taking your example, in my cases, I would have a content block for choosing the page to show all images from. Thus, I would be able to find those references in my content files.
But it’s a completely valid point now that I understand what @texnixe probably meant in the first place and what I got wrong here. And yes, there is most likely hardly anything “maintainable” I could do to catch cases where this information is not coming via content files.
It’s also worth mentioning that this whole idea comes from customers that are used to WordPress, where you have the media section to manage all the files. But I guess there is a case for it. Probably a weekend project at some point.
I think you all helped me already enough to understand that it might not be something I can solve as easily as everything else, but there are ways to do it. So, I consider my questions answered.