Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain Image Name Rather Than Generated Image Filename #55

Open
3200creative opened this issue Jan 21, 2020 · 2 comments
Open

Retain Image Name Rather Than Generated Image Filename #55

3200creative opened this issue Jan 21, 2020 · 2 comments

Comments

@3200creative
Copy link

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.

@mattias-lonn
Copy link

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

@Addibro
Copy link

Addibro commented Jul 5, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants