Skip to main content

Pull Requests Welcome build status Pypi latest version License: AGPL v3

Pelican plugin that insert thumbnails along image links.

However a tested workaround is to use TOR to bypass CloudFront and run the plugin manually on HTML files: torify path/to/image_preview_thumbnailer.py path/to/page.html

Demo page

https://chezsoi.org/lucas/blog/pages/images-libres-de-droits.html

Source Markdown: pages/images-libres-de-droits.md

Usage instructions

To enable this plugin:

  1. Install the package from Pypi: pip install pelican-plugin-image-preview-thumbnailer
  2. Add the plugin to your pelicanconf.py:
PLUGINS = [..., 'image_preview_thumbnailer']
  1. Enable it on the article / pages you wish by inserting this piece of metadata:
Image-preview-thumbnailer: $selector

$selector is a CSS selector to target HTML elements this plugin will parse and look for <a> hyperlinks. It can be for example article if your Pelican template place your pages content in <article> tags, or just body to select the whole page. Several comma-separated values can be provided as CSS selectors to Image-preview-thumbnailer.

Currently this plugin support preview of the following links:

Feel free to submit PRs to add support for more image hosting websites.

Only displaying thumbnails on hover

The initial idea for this plugin was to just add 🖼️ icons after links to images, and then only display thumbnails when hovering on those icons.

To configure this plugin to behave like this, defines the following in your pelicanconf.py:

IMAGE_PREVIEW_THUMBNAILER_INSERTED_HTML = '<span class="previewable"> 🖼️</span><img src="{thumb}" class="preview-thumbnail">'

And insert those CSS rules:

                     .preview-thumbnail { display: none; }
.previewable:hover + .preview-thumbnail { display: block; }

Usage with images lazyloading

There are various Javascript libraries that can provide images lazyloading. If your Pelican template make use of one, you can customize IMAGE_PREVIEW_THUMBNAILER_INSERTED_HTML in order to benefit from it.

For example, to do so using lazysizes, defines the following in your pelicanconf.py:

IMAGE_PREVIEW_THUMBNAILER_INSERTED_HTML = '''<a href="{link}" target="_blank">
    <div class="lazyload" data-noscript=""><noscript><img src="{thumb}" alt=""></noscript></div>
</a>'''

Configuration

Available pelicanconf.py options:

  • IMAGE_PREVIEW_THUMBNAILER_INSERTED_HTML (optional, default: <a href="{link}" target="_blank" class="preview-thumbnail"><img src="{thumb}" class="preview-thumbnail"></a>) : the HTML code to be inserted after every link (<a>) to an image, in order to preview it
  • IMAGE_PREVIEW_THUMBNAILER_IGNORE_404 (optional, default: False) : avoid raising exceptions that abort Pelican when links are found, pointing to images, but they end up in HTTP 404 errors
  • SILENT_HTTP_ERRORS (optional, default: True) : avoid raising exceptions that abort Pelican when links are found, pointing to images, but they end up with an HTTP error, of any kind. An error log message is still produced.
  • IMAGE_PREVIEW_THUMBNAILER_DIR (optional, default: thumbnails) : directory where thumbnail images are stored
  • IMAGE_PREVIEW_THUMBNAILER_EXCEPT_URLS (optional) : comma-separated list of regex patterns of URLs to ignore
  • IMAGE_PREVIEW_THUMBNAILER_THUMB_SIZE (optional, default: 300) : size in pixel of the generated thumbnails.
  • IMAGE_PREVIEW_THUMBNAILER_ENCODING (optional, default: utf-8) : encoding to use to parse HTML files
  • IMAGE_PREVIEW_THUMBNAILER_HTML_PARSER (optional, default: html.parser) : parse that BEautifulSoup will use to parse HTML files
  • IMAGE_PREVIEW_THUMBNAILER_CERT_VERIFY (optional, default: False) : enforce HTTPS certificates verification when sending linkbacks
  • IMAGE_PREVIEW_THUMBNAILER_REQUEST_TIMEOUT (optional, in seconds, default: 3) : time in seconds allowed for each HTTP linkback request before abandon
  • IMAGE_PREVIEW_THUMBNAILER_SELECTOR (optional, default: body) : CSS selector to target HTML elements this plugin will parse and look for <a> hyperlinks.
  • IMAGE_PREVIEW_THUMBNAILER_USERAGENT (optional, default: pelican-plugin-image-preview-thumbnailer) : the User-Agent HTTP header to use while sending notifications.
  • IMAGE_PREVIEW_THUMBNAILER (optional, default: False) : enable the plugin on all your pages

Available metadata entries:

image-preview-thumbnailer: $selector or just true
image-preview-thumbnailer-except-urls: same as IMAGE_PREVIEW_THUMBNAILER_EXCEPT_URLS
image-preview-thumbnailer-ignore-404: same as IMAGE_PREVIEW_THUMBNAILER_IGNORE_404
image-preview-thumbnailer-inserted-html: same as IMAGE_PREVIEW_THUMBNAILER_INSERTED_HTML
image-preview-thumbnailer-thumb-size: same as IMAGE_PREVIEW_THUMBNAILER_THUMB_SIZE

You will also have to define a $PIXABAY_API_KEY environment variable to download images from Pixabay.

Release notes

cf. CHANGELOG.md

Contributing

Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.

To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.

Releasing a new version

With a valid configuration in ~/.config/pypoetry/:

  1. update CHANGELOG.md
  2. bump version in pyproject.toml
  3. poetry build && poetry publish
  4. perform a release on GitGub, including the description added to CHANGELOG.md

Linter & tests

To execute them:

pylint *.py
pytest

Metadata

Release files for pelican-plugin-image-preview-thumbnailer 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pelican-plugin-image-preview-thumbnailer 1.0.9
File Size Uploaded
pelican_plugin_image_preview_thumbnailer-1.0.9.tar.gz 20.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pelican-plugin-image-preview-thumbnailer 1.0.9
File Interpreter ABI Platform
pelican_plugin_image_preview_thumbnailer-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 42.3 kB

Release files / pelican_plugin_image_preview_thumbnailer-1.0.9.tar.gz

Download URL pelican_plugin_image_preview_thumbnailer-1.0.9.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
934f8ef0bcf5c86a5617b09aa88c69ccb4c4a0d06fc3ea1f8417b727dc98e68a
BLAKE2b-256 checksum
How to use checksums
f79a9cf505baeff8877013e5f35692b723153fb3fe49f9b61ab559f325e193e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.10.12 Linux/6.6.87.2-microsoft-standard-WSL2

Release files / pelican_plugin_image_preview_thumbnailer-1.0.9-py3-none-any.whl

Download URL pelican_plugin_image_preview_thumbnailer-1.0.9-py3-none-any.whl
Size 21.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
345ea5d6f0668b94d141753da8d7d0a3e0de9301124d1dbde3be126fa31dcfd6
BLAKE2b-256 checksum
How to use checksums
a18e1c02b1ba548e6c316ab8d881fd8e294e7d263cc4c2937bcb6a6d3385d6f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.10.12 Linux/6.6.87.2-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page