Skip to content

Commit 6dc7f76

Browse files
authored
add(integrations): support integrations with MaterialX theme, fork of Material for Mkdocs (#437)
FYI @jaywhj
2 parents eea4e16 + 1432ed6 commit 6dc7f76

8 files changed

Lines changed: 65 additions & 11 deletions

docs/integrations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Integrations
33
icon: octicons/plug-16
44
---
55

6+
Since version 1.19, the plugin supports both [Material for Mkdocs](https://squidfunk.github.io/mkdocs-material/) (which is in maintenance mode since Nov 11, 2025 and until November 2026) and its fork [MaterialX](https://jaywhj.github.io/mkdocs-materialx/).
7+
68
## Blog plugin (from Material theme)
79

810
Since version 1.17, the plugin integrates with the [Blog plugin (shipped with Material theme)](https://squidfunk.github.io/mkdocs-material/plugins/blog/) (see also [the tutorial about blog + RSS plugins](https://squidfunk.github.io/mkdocs-material/tutorials/blogs/engage/)).

mkdocs_rss_plugin/integrations/theme_material_base.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
class IntegrationMaterialThemeBase:
3434
# attributes
3535
IS_THEME_MATERIAL: bool = False
36+
THEME_NAME: str = "mkdocs"
3637

3738
def __init__(self, mkdocs_config: MkDocsConfig) -> None:
3839
"""Integration instantiation.
@@ -54,10 +55,23 @@ def is_mkdocs_theme_material(
5455
mkdocs_config (Optional[MkDocsConfig]): Mkdocs website configuration object.
5556
5657
Returns:
57-
bool: True if the theme's name is 'material'. False if not.
58+
bool: True if the theme's name is 'material' or 'materialx'. False if not.
5859
"""
5960
if mkdocs_config is None and isinstance(self.mkdocs_config, MkDocsConfig):
6061
mkdocs_config: MkDocsConfig = self.mkdocs_config
6162

62-
self.IS_THEME_MATERIAL = mkdocs_config.theme.name == "material"
63-
return self.IS_THEME_MATERIAL
63+
if isinstance(mkdocs_config, MkDocsConfig):
64+
self.THEME_NAME = (
65+
mkdocs_config.theme.name if mkdocs_config.theme else "mkdocs"
66+
)
67+
self.IS_THEME_MATERIAL = mkdocs_config.theme.name in (
68+
"material",
69+
"materialx",
70+
)
71+
return self.IS_THEME_MATERIAL
72+
73+
logger.warning(
74+
"Cannot check if the theme is Material or not because the MkDocs "
75+
"configuration object is not available."
76+
)
77+
return False

mkdocs_rss_plugin/integrations/theme_material_blog_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ def is_blog_plugin_enabled_mkdocs(self, mkdocs_config: MkDocsConfig | None) -> b
8686
logger.debug("Installed theme is not 'material'. Integration disabled.")
8787
return False
8888

89-
if mkdocs_config.plugins.get("material/blog") is None:
89+
if mkdocs_config.plugins.get(f"{self.THEME_NAME}/blog") is None:
9090
logger.debug("Material blog plugin is not listed in configuration.")
9191
self.IS_BLOG_PLUGIN_ENABLED = False
9292
return False
9393

9494
self.blog_plugin_cfg: BlogPlugin | None = mkdocs_config.plugins.get(
95-
"material/blog"
95+
f"{self.THEME_NAME}/blog"
9696
)
9797

9898
if not self.blog_plugin_cfg.config.enabled:

mkdocs_rss_plugin/integrations/theme_material_social_plugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ def is_social_plugin_enabled_mkdocs(
118118
logger.debug("Installed theme is not 'material'. Integration disabled.")
119119
return False
120120

121-
if not mkdocs_config.plugins.get("material/social"):
121+
if not mkdocs_config.plugins.get(f"{self.THEME_NAME}/social"):
122122
logger.debug("Material Social plugin not listed in configuration.")
123123
return False
124124

125-
social_plugin_cfg = mkdocs_config.plugins.get("material/social")
125+
social_plugin_cfg = mkdocs_config.plugins.get(f"{self.THEME_NAME}/social")
126126

127127
if not social_plugin_cfg.config.enabled:
128128
logger.debug("Material Social plugin is installed but disabled.")
@@ -147,7 +147,7 @@ def is_social_plugin_and_cards_enabled_mkdocs(
147147
if not self.is_social_plugin_enabled_mkdocs(mkdocs_config=mkdocs_config):
148148
return False
149149

150-
social_plugin_cfg = mkdocs_config.plugins.get("material/social")
150+
social_plugin_cfg = mkdocs_config.plugins.get(f"{self.THEME_NAME}/social")
151151

152152
if not social_plugin_cfg.config.cards:
153153
logger.debug(
@@ -212,7 +212,7 @@ def get_social_cards_dir(self, mkdocs_config: MkDocsConfig) -> str:
212212
Returns:
213213
str: The cards_dir if the theme material and the plugin social cards is enabled.
214214
"""
215-
social_plugin_cfg = mkdocs_config.plugins.get("material/social")
215+
social_plugin_cfg = mkdocs_config.plugins.get(f"{self.THEME_NAME}/social")
216216

217217
logger.debug(
218218
"Material Social cards folder in Mkdocs build directory: "
@@ -246,7 +246,7 @@ def get_social_cards_cache_dir(self, mkdocs_config: MkDocsConfig) -> Path:
246246
Returns:
247247
Path: The cache dir if the theme material and the plugin social cards is enabled.
248248
"""
249-
social_plugin_cfg = mkdocs_config.plugins.get("material/social")
249+
social_plugin_cfg = mkdocs_config.plugins.get(f"{self.THEME_NAME}/social")
250250

251251
if (
252252
Path(social_plugin_cfg.config.cache_dir)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ test = [
7070
"feedparser>=6.0.12,<6.1",
7171
"jsonfeed-util>=1.2,<2",
7272
"mkdocs-material[imaging]>=9.7,<9.8",
73+
"mkdocs-materialx[imaging]>=10.1.3,<11",
7374
"pytest-cov>=6.9.1,<8",
7475
"validator-collection>=1.5,<1.6",
7576
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
site_name: Test RSS Plugin
2+
site_description: Test social cards support in RSS with blog plugin also enabled
3+
site_url: https://guts.github.io/mkdocs-rss-plugin
4+
5+
plugins:
6+
- blog:
7+
blog_dir: blog
8+
- rss:
9+
match_path: blog/posts/.*
10+
pretty_print: true
11+
- social:
12+
enabled: true
13+
cards: true
14+
15+
theme:
16+
name: materialx

tests/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def test_plugin_config_image(self):
157157

158158
def test_plugin_config_through_mkdocs(self):
159159
for config_filepath in self.config_files:
160-
plg_cfg = self.get_plugin_config_from_mkdocs(config_filepath, "rss")
161160
print(config_filepath)
161+
plg_cfg = self.get_plugin_config_from_mkdocs(config_filepath, "rss")
162162
self.assertIsInstance(plg_cfg, Config)
163163

164164

tests/test_integrations_material_social_cards.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,27 @@ def test_plugin_config_social_cards_enabled_with_blog_plugin(self):
137137
)
138138
self.assertTrue(integration_social_cards.IS_ENABLED)
139139

140+
def test_plugin_config_materialx_social_cards_enabled_with_blog_plugin(self):
141+
# default reference
142+
cfg_mkdocs = load_config(
143+
str(
144+
Path(
145+
"tests/fixtures/mkdocs_materialx_item_image_social_cards_blog.yml"
146+
).resolve()
147+
)
148+
)
149+
150+
integration_social_cards = IntegrationMaterialSocialCards(
151+
mkdocs_config=cfg_mkdocs
152+
)
153+
self.assertTrue(integration_social_cards.IS_THEME_MATERIAL)
154+
self.assertTrue(integration_social_cards.IS_SOCIAL_PLUGIN_ENABLED)
155+
self.assertTrue(integration_social_cards.IS_SOCIAL_PLUGIN_CARDS_ENABLED)
156+
self.assertTrue(
157+
integration_social_cards.integration_material_blog.IS_BLOG_PLUGIN_ENABLED
158+
)
159+
self.assertTrue(integration_social_cards.IS_ENABLED)
160+
140161
def test_plugin_config_social_cards_enabled_with_directory_urls_disabled(self):
141162
"""Test case described in https://github.com/Guts/mkdocs-rss-plugin/issues/319."""
142163
# default reference

0 commit comments

Comments
 (0)