Skip to content

Commit 01e55b5

Browse files
committed
improve(build): check the Material theme flavor and handle fallback
1 parent f4ae5b2 commit 01e55b5

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

hooks/mkdocs/G000_load_subconfigs.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
# standard library
88
import logging
99
from pathlib import Path
10-
from typing import Literal
10+
from typing import Literal, Optional
1111

1212
# 3rd party
1313
import mkdocs.plugins
14+
from material import __version__ as material_version
1415
from mkdocs.config.defaults import MkDocsConfig
1516
from mkdocs.structure.pages import Page
1617
from mkdocs.utils.meta import get_data
@@ -60,6 +61,25 @@ def get_latest_content(
6061
return output_contents_list
6162

6263

64+
def is_mkdocs_theme_material_insiders() -> Optional[bool]:
65+
"""Check if the material theme is community or insiders edition.
66+
67+
Returns:
68+
bool: True if the theme is Insiders edition. False if community.
69+
"""
70+
if material_version is not None and "insiders" in material_version:
71+
logger.debug("Material theme edition INSIDERS")
72+
return True
73+
else:
74+
logger.debug("Material theme edition COMMUNITY")
75+
return False
76+
77+
78+
# ###########################################################################
79+
# ########## Hooks #################
80+
# ##################################
81+
82+
6383
@mkdocs.plugins.event_priority(10)
6484
def on_config(config: MkDocsConfig) -> MkDocsConfig:
6585
"""The config event is the first event called on build and
@@ -71,22 +91,35 @@ def on_config(config: MkDocsConfig) -> MkDocsConfig:
7191
Args:
7292
config (config_options.Config): global configuration object
7393
74-
Raises:
75-
FileExistsError: if the template for the RSS feed is not found
76-
PluginError: if the 'date_from_meta.default_time' format does not comply
77-
7894
Returns:
7995
MkDocsConfig: global configuration object
8096
"""
8197
# determine the website flavor
8298
if config.get("config_file_path") == "mkdocs.yml":
8399
config["extra"]["website_flavor"] = "insiders"
84100
elif config.get("config_file_path") == "mkdocs-free.yml":
85-
config["extra"]["website_flavor"] = "free"
101+
config["extra"]["website_flavor"] = "community"
86102
else:
87103
config["extra"]["website_flavor"] = "minimal"
88104

89-
logger.info(f"Version du site : {config.get('extra').get('website_flavor')}")
105+
# check if insiders version is installed
106+
if (
107+
config["extra"]["website_flavor"] == "insiders"
108+
and not is_mkdocs_theme_material_insiders()
109+
):
110+
logger.warning(
111+
f"Le fichier {config.get('config_file_path')} contient des paramètres ou "
112+
"plugins uniquement disponibles dans la version Insiders (payante) du thème "
113+
"Material. Or c'est la version community (gratuite) qui est installée : "
114+
f"{material_version}. C'est donc la version communautaire (gratuite) qui "
115+
"sera utilisée pour générer le site web."
116+
)
117+
config["extra"]["website_flavor"] = "community"
118+
119+
logger.info(
120+
f"Génération du site {config.get('site_name')} "
121+
f"en version {config.get('extra').get('website_flavor').upper()}"
122+
)
90123

91124
# latest contents
92125
latest_contents: dict = {"articles": [], "rdp": []}

0 commit comments

Comments
 (0)