Skip to content

mkdocs_nype.plugins.webp_images.plugin

Synopsis

MkDocs plugin to convert images to WebP format

This plugin converts images concurrently and recursively to not block the main thread and injects the web image path during Markdown path validation / resolution to not parse HTML output with regex.

Parts adapted based on: - https://github.com/mur4d1n-lib/mkdocs-images-to-webp by mur4d1n (MIT) - https://github.com/squidfunk/mkdocs-material/tree/master/material/plugins/social by squidfunk (MIT) - https://gitlab.com/Shoun2137/ztexipy by Shoun2137 (GPLv3)

MIT License Kamil Krzyśków (HRY) for Nype (npe.cm) and Fiori Tracker (fioritracker.org)

PLUGIN_NAME

PLUGIN_NAME: str = 'webp_images'

Name of the plugin

LOG

LOG: PrefixedLogger = PrefixedLogger(PLUGIN_NAME, getLogger(f'mkdocs.plugins.{PLUGIN_NAME}'))

Logger instance for this plugin.

WebpImagesPlugin

WebpImagesPlugin()

Bases: BasePlugin[WebpImagesConfig]

executor

executor: ThreadPoolExecutor = None

promises

promises: list[Future] = []

extensions

extensions: list[str] = None

old_file_map

old_file_map: dict[str, File] = {}

cache_index

cache_index: dict[str, str] = {}

processed_images

processed_images: set[str] = set()

cache_index_file

cache_index_file: Path = None

cache_base

cache_base: Path = None

cache_image_base

cache_image_base: Path = None

site_dir_path

site_dir_path: Path = None

on_config

on_config(config)

on_files

on_files(files, /, *, config)

_convert_image

_convert_image(src: str, dest: Path, cache_dest: Path | None, name: str)

on_post_build

on_post_build(*, config)

on_shutdown

on_shutdown()

get_image_hash_key

get_image_hash_key(src: str, algo: str = 'sha256', chunk_size=4096)

Load the file via stream and calculate hash during the process

wrap_path_to_url

wrap_path_to_url(func, *, extensions)

Wrap mkdocs.structure.pages._RelativePathTreeprocessor.path_to_url logic to swap in WebP paths

wrap_url_filter

wrap_url_filter(func, *, extensions)

Wrap mkdocs.utils.templates.url_filter logic to swap in WebP paths

wrap_run

wrap_run(func, *, extensions)

Wrap mkdocs.structure.pages._RelativePathTreeprocessor.run logic to swap in WebP paths