blueswen / mkdocs-glightbox

A MkDocs plugin supports image lightbox (zoom effect) with GLightbox.
https://blueswen.github.io/mkdocs-glightbox/
MIT License
115 stars 14 forks source link

Conflict with the privacy plugin of Material theme #25

Closed Guts closed 6 months ago

Guts commented 8 months ago

This issue is the continuation of this one: https://github.com/squidfunk/mkdocs-material/issues/6248 where you can find every details and a reproducible example.

In a nutshell:

See this comment from @squidfunk:

I've investigated and came to the conclusion that it does not make sense to fix this on our side. Here's why:

Problem

The mkdocs-glightbox plugin currently detects img elements during build time (after the site has been rendered as HTML) and wraps them with a anchor elements. As already noted in #6248 (comment), the privacy plugin only considers assets that are actually rendered to be downloaded. However, the glightbox plugin will wrap the image in an anchor and set href to the image. Normally, an a is a link to an external or internal resource – nothing that is rendered or downloaded without the users consent, thus not under GDPR. This is beyond the scope of the privacy plugin.

Why? Because if we would start downloading resources that are referenced in a[href] attributes, we would need another way to tell the plugin what not to download. Otherwise the plugin will try to download all external resources, which will make configuration much more challenging and the final site will probably blow up in size.

Possible solution

IMHO, there's no need for the glightbox plugin to wrap the img elements during build time – glightbox needs JavaScript to function (open the inspector when you click on an image, and you will see that the JavaScript changes several properties, e.g. on the body). As there's no possibility to make it work without JavaScript (correct me if I'm wrong), I think it's a better idea to defer wrapping of image elements into the browser. The glightbox plugin could just mark elements with a specific class or attribute, e.g. data-glightbox, and provide a small JavaScript that wraps the img elements when the page has loaded. This would mean the correct image would be picked up every time.

This would not only solve the problem at hand, but also be easier to extend to other resources to be presented in the ligtbox, because very soon, the optimize plugin will receive the capability to generate multiple variants of images and wrap them in picture tags. The glightbox plugin could the pick the appropriate source in the picture tag.

If you need help getting this to work, @blueswen, let me know. Wrapping an element in JavaScript is quite simple..

Closing as upstream issue.

blueswen commented 7 months ago

Hi @Guts,

In the latest version v0.3.5, mkdocs-glightbox is compatible with the privacy plugin of Material for MkDocs insiders.

I took Martin's advice to update the a tag href when the HTML page loaded with javascript, which will ensure the href is the same as the updated src from the img tag.

Please let me know if this solves your issue.