Skip to content

Commit 4ed40ea

Browse files
committed
fix(integration): Material Social Card URI was wrong for Material blog posts when diretcory URL are disabled at Mkdocs level
Bug partially fixed in #354 then reintroduced in #418
1 parent 6608ccb commit 4ed40ea

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

mkdocs_rss_plugin/integrations/theme_material_social_plugin.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(self, mkdocs_config: MkDocsConfig, switch_force: bool = True) -> No
8585

8686
# if enabled, save some config elements
8787
if self.IS_ENABLED:
88+
self.mkdocs_use_directory_urls = mkdocs_config.use_directory_urls
8889
self.mkdocs_site_url = mkdocs_config.site_url
8990
self.mkdocs_site_build_dir = mkdocs_config.site_dir
9091
self.social_cards_dir = self.get_social_cards_dir(
@@ -99,10 +100,6 @@ def __init__(self, mkdocs_config: MkDocsConfig, switch_force: bool = True) -> No
99100

100101
self.load_cache_cards_manifest()
101102

102-
# store some attributes used to compute social card hash
103-
self.site_name = mkdocs_config.site_name
104-
self.site_description = mkdocs_config.site_description or ""
105-
106103
def is_social_plugin_enabled_mkdocs(
107104
self, mkdocs_config: MkDocsConfig | None = None
108105
) -> bool:
@@ -383,10 +380,17 @@ def get_social_card_url_for_page(
383380
self.integration_material_blog.IS_BLOG_PLUGIN_ENABLED
384381
and self.integration_material_blog.is_page_a_blog_post(mkdocs_page)
385382
):
386-
page_social_card = (
387-
f"{mkdocs_site_url}assets/images/social/"
388-
f"{Path(mkdocs_page.dest_uri).with_suffix('.png')}"
389-
)
383+
if self.mkdocs_use_directory_urls:
384+
# see: https://github.com/Guts/mkdocs-rss-plugin/issues/319
385+
page_social_card = (
386+
f"{mkdocs_site_url}{self.social_cards_dir}/"
387+
f"{Path(mkdocs_page.dest_uri).parent.with_suffix('.png')}"
388+
)
389+
else:
390+
page_social_card = (
391+
f"{mkdocs_site_url}{self.social_cards_dir}/"
392+
f"{Path(mkdocs_page.dest_uri).with_suffix('.png')}"
393+
)
390394
else:
391395
page_social_card = (
392396
f"{mkdocs_site_url}{self.social_cards_dir}/"

0 commit comments

Comments
 (0)