add zensical workflow

This commit is contained in:
Oliver Walters committed 2026-11-12 02:32:19 +00:00
1 parent af5055b33e
commit e479fbf95e
4 files changed
+462 -3

No files matched your search

+39 -1
View File
@@ -1,9 +1,11 @@
"""Main entry point for the documentation build process."""
import importlib.util
import json
import logging
import os
import subprocess
import sys
import textwrap
from pathlib import Path
from typing import Literal, Optional
@@ -161,9 +163,45 @@ def get_build_environment() -> Optional[str]:
return 'master'
def apply_hook_config(env):
"""Provide values normally injected by the 'on_config' mkdocs hook.
Zensical does not support mkdocs hooks, so 'config.releases',
'config.assets_dir' etc are never set. When they are missing, run the
hook ourselves and inject the results into the template 'config' variable.
Zensical re-executes this module for every page, so the hook result is
cached on a module stored in sys.modules (which persists across pages).
"""
template_config = env.variables.get('config')
if template_config is None or 'releases' in template_config:
# Running under mkdocs - the hook has already been applied
return
hooks = sys.modules.get('inventree_docs_hooks')
if hooks is None:
spec = importlib.util.spec_from_file_location(
'inventree_docs_hooks', here.joinpath('docs', 'hooks.py')
)
hooks = importlib.util.module_from_spec(spec)
spec.loader.exec_module(hooks)
hooks.CACHED_CONFIG = hooks.on_config({
'site_url': template_config.get('site_url')
})
sys.modules['inventree_docs_hooks'] = hooks
for key in ['releases', 'assets_dir', 'readthedocs', 'version_banner']:
if key in hooks.CACHED_CONFIG:
template_config[key] = hooks.CACHED_CONFIG[key]
def define_env(env):
"""Define custom environment variables for the documentation build process."""
config = env.config
apply_hook_config(env)
config = env.variables.get('config') or env.config
assets_dir = config.get('assets_dir', None)
if assets_dir is None: