Hey, Prismic community! A while back, @samlittlefair helped us figure out how to find all documents using a particular slice:
This has been a huge help for understanding how the slices we build are actually being used (or if they're being used) across a ≈500-page site.
Is there a similar technical pathway for us to query for all active/unarchived documents using a particular media file? I'd also be interested in querying for media files that aren't used in any active/unarchived documents.
I don't think there is way an easy, straightforward way to get the list of unused images; in fact, the missing part is how to get a full list of the images in your media library.
Once you have that, then you can use a similar script to the one @samlittlefair has developed to get the subset of images that are not used if you fetch all docs.
So a hacky workaround to get the full list of images would be to run a JQuery script in your browser console to fetch all the names of the files, such:
Thanks, Fares! You answered my second question but not my first (the one in the title of the post). Is there a way for us to query all documents using a particular media file? The desired output would list all the documents using a particular media file.
Well, I don't think it is possible to find all documents using a particular media file, at least no easy way to do that other than fetch all documents as a JSON and deep search this JSON with some library to find those document that uses that image that is because the fulltext predicate in [fulltext(document,"test.jpg")]" doesn't look in the URLs nor in the image alt.
Got it—thanks for confirming! Given that customers have no way to create this query themselves, I think it strengthens the case for Prismic clarifying this within their own UI. Clarifying the relationships between content (media, documents, etc.) seems like an important part of a CMS—or at the very least, one that customers can grow with.