sachinchoolur / lightGallery

A customizable, modular, responsive, lightbox gallery plugin.
https://www.lightgalleryjs.com/
Other
6.55k stars 1.29k forks source link

FR: Support for Query Parameters in Hash plugin #1673

Open BenAlanSouthall opened 6 days ago

BenAlanSouthall commented 6 days ago

Summary

The hash plugin is a very nice feature. I'd like to be able to change query arguments in the URL, instead of just the hash-location, so that I have a unique URL I can filter on later.

Basic example

I guess the most flexible way of implementing this might be some sort of template I can provide in the options for the hash plugin. Perhaps a callback function that receives the gallery and slide numbers and generates the URL, or a string template that will be interpolated. Not a JS developer so there may be more idiomatic ways.

Motivation

I host my site statically. I'd like to use the images in the gallery as og:image links for social media, and I'd also like for the user to be able to share either by copying the URL the old-fashioned way (like I normally do ;) ) and using share buttons - so I want to rely on using the URL, rather than the custom content for the sharing URL that opens in a new tab with the share plugin. This way, if someone just copies a link to the page when one of the images in the gallery is open, I can have the social card rendered properly for that image when they paste it into some platform and write a post.

I can use some server-side routing to detect the scraper's user-agent and filter those out to return a short page containing the og:image tag for just that image, without displaying the main page. However, the social media scrapers appear to strip the document location from the URL when they go to collect the page info and generate the preview.

Therefore, if I can change the query argument on the page, I have a unique URL that the scrapers will use, and can redirect them to the given social card image.