unpic icon indicating copy to clipboard operation
unpic copied to clipboard

Cloudinary SEO Suffix

Open colbyfayock opened this issue 2 years ago • 2 comments

Cloudinary has support for something called an SEO suffix. The idea is, you can customize the end of your image URL where the public ID would normally be, to add something SEO friendly.

Think instead of something like .../image/upload/oaisnd143, you can do .../images/oaisnd143/cool-image-with-stuff

I just added support for it in my little tool: https://github.com/colbyfayock/cloudinary-util/pull/19

Here's the updated regex:

https://github.com/colbyfayock/cloudinary-util/blob/main/packages/util/src/lib/cloudinary.ts#L2

HOWEVER

my regex requires a version in the URL so make parsing more predictible which I dont think yours is currently doing. Might be able to still get away with it, but regex isn't my thing, which is why I'm not putting in a PR instead of this 🙈

Relevant docs: https://cloudinary.com/documentation/advanced_url_delivery_options#seo_friendly_media_asset_urls

colbyfayock avatar Feb 27 '23 01:02 colbyfayock

Oh and if it helps, heres a regex101 that helped me visualize: https://regex101.com/r/TqK3do/1

colbyfayock avatar Feb 27 '23 01:02 colbyfayock

Oh and if it helps, heres a regex101 that helped me visualize: https://regex101.com/r/TqK3do/1

Thank you for sharing the regex code, it was not working for dynamic SEO suffix due to the fact, the deliveryType group was restrained with default options, in cloudinary page, there is an option to mainuplate the URL by changing from 'image' to 'images' and removing 'upload/version'/ and add a suffix for seo.

Example:

https://res.cloudinary.com/cloudname/image/upload/v1698107224/location_jr0gqg.jpg

to

https://res.cloudinary.com/cloudname/location_jr0gqg.jpg

to

https://res.cloudinary.com/cloudname/images/location_jr0gqg/Anyname.jpg

Anyways, I have modified the code and added ? to make the selection optional. image

/https?:\/\/(?<host>[^\/]+)\/(?<cloudName>[^\/]+)\/(?<assetType>image|images|video|videos|raw|files)\/?(?<deliveryType>upload|fetch|private|authenticated|sprite|facebook|twitter|youtube|vimeo)?\/?(?<signature>s--([a-zA-Z0-9\_\-]{8}|[a-zA-Z0-9\_\-]{32})--)?\/?(?<transformations>(?:[^_\/]+_[^,\/]+,?\/?)*\/)*(?<version>v\d+|\w{1,2})\/(?<publicId>[^\s]+)$/gm

I would hope if the developer @ascorbic update the repo and fix the code

image

Many thanks

mohdlatif avatar Oct 24 '23 03:10 mohdlatif