Skip to content

mkdocs_nype.plugins.sap_icons.plugin

Synopsis

MkDocs plugin made to add SAP icons to the Material emoji index.

This plugin was formerly a hook:

The icons are taken from the https://github.com/SAP/ui5-webcomponents/ repository. ICON_JSONS_URLS at the bottom of the file store URLs to fetch that contain JSON file with SVG paths. Those paths are injected into a <svg> tag with a viewBox of 0 0 512 512

The plugin overrides the FileSystemLoader.get_source function to inject the SVGs when accessed via Jinja templates. The logic tries to load the files from the filesystem, but then falls back to processing the loaded virtual indexes.

Additionally, there are some Nype icons/emojis injected as well.

MIT License 2024 Kamil Krzyśków (HRY) for Nype (npe.cm)

PLUGIN_NAME

PLUGIN_NAME: str = 'sap_icons'

Name of the plugin

CACHE_DIR

CACHE_DIR: Path = None

Cache directory to put downloaded files, set later in event

DOWNLOAD_NEW_PER_WEEK

DOWNLOAD_NEW_PER_WEEK: bool = True

Boolean to decide if the files should update after a week

WEEK

WEEK: int = week

Integer with the week value from ISO calendar

ICON_JSONS_URLS

ICON_JSONS_URLS: list[str] = ['https://raw.githubusercontent.com/SAP/ui5-webcomponents/main/packages/icons/src/v5/SAP-icons.json']

List with links to JSON files that contain SVG icon paths

ICON_INDEXES

ICON_INDEXES: list[dict[str, dict]] = []

Global list to store the indexes, filled later in event

LOG

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

Logger instance for this plugin.

MATERIAL_INDEX_UPDATED

MATERIAL_INDEX_UPDATED: bool = False

Boolean flag to keep track of index modification

NEW_ICON_PREFIX

NEW_ICON_PREFIX: str = ':ext-'

Prefix for the added icons to avoid overrides

SapIconsPlugin

Bases: BasePlugin[SapIconsConfig]

on_config

on_config(config: MkDocsConfig)

on_serve

on_serve(server: LiveReloadServer, /, *, config: MkDocsConfig, builder: Callable[..., Any]) -> LiveReloadServer | None

ServeHelper

run_once

run_once = False

Flag to keep track if the server was run

wrap_get_source

wrap_get_source(func)

template_from_index

template_from_index(template: str)

get_svg_with_path

get_svg_with_path(path: str)

emoji_decorator

emoji_decorator(func)

add_nype_icons

add_nype_icons()

load_indexes

load_indexes()

download_icons

download_icons()