gatsby-source-sanity icon indicating copy to clipboard operation
gatsby-source-sanity copied to clipboard

Retain Image Name Rather Than Generated Image Filename

Open 3200creative opened this issue 5 years ago • 2 comments

I'm optimizing images for SEO and can't seem to solve this issue:

I'd like to keep the image filename somewhere within the final images filenames I've found the option for 'storeOriginalFilename' however I'm having trouble passing it to the final filenames of the generated images.


Example of sanity auto-generated filenames being indexed with Google: If you google 7b1b7cc7a4cf094b24cfd1ea6a6fa224865bc9e0 you'll get the incredible hulk due to the filename at: https://www.knutmelvaer.no/


Is there an example or documentation on how to accomplish this? Thanks in advance.

3200creative avatar Jan 21 '20 17:01 3200creative

Sanity lets you add a filename at the end of the url and return the originalFilename (or any wanted name) like this: https://cdn.sanity.io/images/{project-id}/{dataset}/{hashed-name}/{originalFilename}?params..

Your image URL would in this case be: https://cdn.sanity.io/images/ndjrels0/production/7b1b7cc7a4cf094b24cfd1ea6a6fa224865bc9e0-1200x800.png/the-incredible-hulk.webp?fm=webp

mattias-lonn avatar May 13 '21 23:05 mattias-lonn

Hi!

@mattias-lonn how would you get hold of the {originalFilename} in this case? Lets say that you grok an asset reference by doing asset->{url} or something, then you would get the something like url_path_/68167e1c7d2bc14d7be0a0bc01e2bb36e9ec76c2.yaml right. But let's say the uploaded name is test.yaml, where would you get that variable?

Thanks, Andreas

Addibro avatar Jul 05 '21 09:07 Addibro