Skip to content

mkdocs_nype.plugins.server_redirects.plugin

Synopsis

MkDocs plugin made to generate file with back-end redirects

The best way to handle a redirection is to respond with a 301 status code and point the traffic to that location, instead of loading a 200 / 404 status code page with a meta-refresh / JavaScript redirect.

This plugin generates an Nginx compliant redirects mapping, which is then loaded after deployment.

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

PLUGIN_NAME

PLUGIN_NAME: str = 'server_redirects'

Name of the plugin

LOG

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

Logger instance for this plugin.

ServerRedirectsPlugin

ServerRedirectsPlugin()

Bases: BasePlugin[ServerRedirectsConfig]

redirects_plugin

redirects_plugin = None

output_redirects

output_redirects: dict[str, str] = {}

on_config

on_config(config: MkDocsConfig) -> MkDocsConfig | None

on_env

on_env(env: Environment, /, *, config: MkDocsConfig, files: Files) -> Environment | None

Create the server redirects here, to allow other plugins to inject them before on_env

convert_filepath_to_url

convert_filepath_to_url(filepath: str)

Mainly used for the old non-existent file, as we take the file.url for existing files

on_post_build

on_post_build(*, config: MkDocsConfig) -> None

Save the file after the build

save_nginx

save_nginx(config: MkDocsConfig)