@@ -89,6 +89,9 @@ def __init__(self, mkdocs_config: MkDocsConfig, switch_force: bool = True) -> No
89
89
if self .IS_ENABLED :
90
90
self .mkdocs_site_url = mkdocs_config .site_url
91
91
self .mkdocs_site_build_dir = mkdocs_config .site_dir
92
+ self .social_cards_dir = self .get_social_cards_dir (
93
+ mkdocs_config = mkdocs_config
94
+ )
92
95
self .social_cards_assets_dir = self .get_social_cards_build_dir (
93
96
mkdocs_config = mkdocs_config
94
97
)
@@ -205,15 +208,15 @@ def load_cache_cards_manifest(self) -> Optional[dict]:
205
208
206
209
return self .CARDS_MANIFEST
207
210
208
- def get_social_cards_build_dir (self , mkdocs_config : MkDocsConfig ) -> Path :
209
- """Get Social Cards folder within Mkdocs site_dir.
211
+ def get_social_cards_dir (self , mkdocs_config : MkDocsConfig ) -> str :
212
+ """Get Social Cards folder relative to Mkdocs site_dir.
210
213
See: https://squidfunk.github.io/mkdocs-material/plugins/social/#config.cards_dir
211
214
212
215
Args:
213
216
mkdocs_config (MkDocsConfig): Mkdocs website configuration object.
214
217
215
218
Returns:
216
- str: True if the theme material and the plugin social cards is enabled.
219
+ str: The cards_dir if the theme material and the plugin social cards is enabled.
217
220
"""
218
221
social_plugin_cfg = mkdocs_config .plugins .get ("material/social" )
219
222
@@ -222,7 +225,22 @@ def get_social_cards_build_dir(self, mkdocs_config: MkDocsConfig) -> Path:
222
225
f"{ social_plugin_cfg .config .cards_dir } ."
223
226
)
224
227
225
- return Path (social_plugin_cfg .config .cards_dir ).resolve ()
228
+ return social_plugin_cfg .config .cards_dir
229
+
230
+ def get_social_cards_build_dir (self , mkdocs_config : MkDocsConfig ) -> Path :
231
+ """Get Social Cards folder within Mkdocs site_dir.
232
+ See: https://squidfunk.github.io/mkdocs-material/plugins/social/#config.cards_dir
233
+
234
+ Args:
235
+ mkdocs_config (MkDocsConfig): Mkdocs website configuration object.
236
+
237
+ Returns:
238
+ Path: Absolute path of the assets dir if the theme material and the plugin
239
+ social cards is enabled.
240
+ """
241
+ cards_dir = self .get_social_cards_dir (mkdocs_config = mkdocs_config )
242
+
243
+ return Path (cards_dir ).resolve ()
226
244
227
245
def get_social_cards_cache_dir (self , mkdocs_config : MkDocsConfig ) -> Path :
228
246
"""Get Social Cards folder within Mkdocs site_dir.
@@ -232,7 +250,7 @@ def get_social_cards_cache_dir(self, mkdocs_config: MkDocsConfig) -> Path:
232
250
mkdocs_config (MkDocsConfig): Mkdocs website configuration object.
233
251
234
252
Returns:
235
- str: True if the theme material and the plugin social cards is enabled.
253
+ Path: The cache dir if the theme material and the plugin social cards is enabled.
236
254
"""
237
255
social_plugin_cfg = mkdocs_config .plugins .get ("material/social" )
238
256
self .social_cards_cache_dir = Path (social_plugin_cfg .config .cache_dir ).resolve ()
@@ -372,19 +390,12 @@ def get_social_card_url_for_page(
372
390
if mkdocs_site_url is None and self .mkdocs_site_url :
373
391
mkdocs_site_url = self .mkdocs_site_url
374
392
375
- # if page is a blog post
376
- if (
377
- self .integration_material_blog .IS_BLOG_PLUGIN_ENABLED
378
- and self .integration_material_blog .is_page_a_blog_post (mkdocs_page )
379
- ):
380
- page_social_card = (
381
- f"{ mkdocs_site_url } assets/images/social/"
382
- f"{ Path (mkdocs_page .file .dest_uri ).parent } .png"
383
- )
384
- else :
385
- page_social_card = (
386
- f"{ mkdocs_site_url } assets/images/social/"
387
- f"{ Path (mkdocs_page .file .src_uri ).with_suffix ('.png' )} "
388
- )
393
+ # As of mkdocs-material 9.6.5, social cards are always stored in the
394
+ # matching src path in the build folder, regardless of the page type.
395
+ page_social_card = (
396
+ f"{ mkdocs_site_url } { self .social_cards_dir } /"
397
+ f"{ Path (mkdocs_page .file .src_uri ).with_suffix ('.png' )} "
398
+ )
399
+ logger .debug (f"Use social card url: { page_social_card } " )
389
400
390
401
return page_social_card
0 commit comments