77# standard library
88import logging
99from pathlib import Path
10- from typing import Literal
10+ from typing import Literal , Optional
1111
1212# 3rd party
1313import mkdocs .plugins
14+ from material import __version__ as material_version
1415from mkdocs .config .defaults import MkDocsConfig
1516from mkdocs .structure .pages import Page
1617from 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 )
6484def 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