From 77a08d987fbf1c330afab7fe2317265a558c91e3 Mon Sep 17 00:00:00 2001 From: Martin Donath Date: Sat, 28 Mar 2026 12:35:07 +0100 Subject: [PATCH] feature: add support for `mike` Signed-off-by: squidfunk --- python/zensical/config.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/python/zensical/config.py b/python/zensical/config.py index 74d47ad..d77a9bd 100644 --- a/python/zensical/config.py +++ b/python/zensical/config.py @@ -27,10 +27,11 @@ import hashlib import importlib import os import pickle +import sys from importlib.util import find_spec from pathlib import Path from typing import IO, TYPE_CHECKING, Any -from urllib.parse import urlparse +from urllib.parse import urljoin, urlparse import yaml from click import ClickException @@ -173,6 +174,10 @@ def _apply_defaults(config: dict, path: str) -> dict: set_default(config, "dev_addr", "localhost:8000", str) set_default(config, "copyright", None, str) + # Set defaults for versioning with mike + set_default(config, "remote_branch", "gh-pages", str) + set_default(config, "remote_name", "origin", str) + # Set defaults for repository settings set_default(config, "repo_url", None, str) set_default(config, "repo_name", None, str) @@ -818,6 +823,29 @@ def _convert_plugins(value: Any, config: dict) -> dict: } ) + # Mike sets an environment variable for us to determine whether the build + # is triggered from mike. If it is, we read the plugin configuration, if + # any, and mirror mike's functionality in adjusting the configuration when + # building the site, while only allowing for our theme at the moment. + version = os.environ.get("MIKE_DOCS_VERSION") + if version and config.get("site_url"): + mike = set_default( + plugins, + "mike", + { + "alias_type": "symlink", + "redirect_template": None, + "deploy_prefix": "", + "canonical_version": None, + }, + dict, + ) + + # Copied and adapted from mike's plugin implementation + if mike["canonical_version"] is not None: + version = mike["canonical_version"] + config["site_url"] = urljoin(config["site_url"], version) + # Now, add another level of indirection, by moving all plugin configuration # into a `config` property, making it compatible with Material for MkDocs. for name, data in plugins.items():