mkdocs_nype
Synopsis
MkDocs Nype theme, based on the Material for MkDocs theme.
This __init__.py
file gets loaded by MkDocs before plugins are initialized. Therefore, this is a good place to monkey-patch changes into the build process.
Consider both nype/
and material/
namespaces when loading plugins
Due to how themename/pluginname
namespaces work to make using Nype projects more convenient we change the logic of how namespaces are resolved. pluginname
will be resolved in order:
nype/pluginname
material/pluginname
pluginname
Inject predefined plugins for loading even when they're not in mkdocs.yml
Instead of requiring to enable a plugin in a project mkdocs.yml
, enable it by default. This allows nype_tweaks
to operate as a project manager for the entirety of the event loop.
Extend Material theme plugins directly
Instead of configuring other plugins and overriding internals of mkdocs-material plugins during the event loop, extend them before they're loaded into "Python MkDocs memory". This allows to directly modify how the PluginConfig is resolved, therefore allows to add options directly under the extended plugin in mkdocs.yml
instead of under another plugin.
MIT License 2024 Kamil Krzyśków (HRY) for Nype (npe.cm)
issue_counter
This is fetched in nype_tweaks
to trigger --strict
flag based on __init__.py
WANTED_PLUGINS
WANTED_PLUGINS: tuple[PluginEntry] = (PluginEntry('nype_tweaks', scope='nype'), PluginEntry('minify_html', config={'enabled': _parse_env_flag(), 'keep_html_and_head_opening_tags': True, 'keep_closing_tags': True}), PluginEntry('webp_images', scope='nype', config={'enabled': _parse_env_flag(), 'ignore_paths': dedent(strip())}))
Tuple of wanted PluginEntries. Scope can be None. Config can be None to use defaults.
patch_plugin_loading
Monkey patches the load_plugin_with_namespace
function after confirming that the hash is the same.
load_plugin_with_namespace
Adapted code from the MkDocs 1.6.0 repository. Modification adds material/pluginname
fallback.
patch_default_plugins_auto_load
Monkey patches the run_validation
function after confirming that the hash is the same.
run_validation
Adapted code from the MkDocs 1.6.0 repository. Modification adds nype_tweaks
plugin when missing.
_get_checksum
Remove comments, spaces, turn lowercase to get a minified token and return a sha256 hash from it
_parse_env_flag
Parse environment variable as a flag for injected plugin config