From 8f34488191688f0f7edf266eec9a4899fca8bec8 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Mon, 2 Dec 2024 15:04:33 +0100 Subject: [PATCH 1/2] feature(integration): make the integration with Material Blog configurable through an option --- README.md | 1 + docs/configuration.md | 10 ++++++++++ mkdocs_rss_plugin/config.py | 1 + mkdocs_rss_plugin/integrations/theme_material_base.py | 2 +- mkdocs_rss_plugin/plugin.py | 10 ++++++++++ mkdocs_rss_plugin/util.py | 7 +++++++ tests/fixtures/mkdocs_items_material_blog_enabled.yml | 4 +++- 7 files changed, 33 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 83b8300..46b0054 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ plugins: utm_medium: "RSS" utm_campaign: "feed-syndication" use_git: true + use_material_blog: true use_material_social_cards: true ``` diff --git a/docs/configuration.md b/docs/configuration.md index 125f3e6..0155233 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -596,6 +596,16 @@ Default: `true`. ---- +### :material-newspaper-variant-outline: `use_material_blog`: enable/disable integration with Material Blog plugin { #use_material_blog } + +If `false`, the integration with the Blog plugin is disabled. + +Default: `true`. + +> See [the related section in integrations page](./integrations.md#blog-plugin-from-material-theme). + +---- + ### :material-cards: `use_material_social_cards`: enable/disable integration with Material Social Cards plugin { #use_material_social_cards } If `false`, the integration with Social Cards is disabled. diff --git a/mkdocs_rss_plugin/config.py b/mkdocs_rss_plugin/config.py index 2531728..bc37a95 100644 --- a/mkdocs_rss_plugin/config.py +++ b/mkdocs_rss_plugin/config.py @@ -60,4 +60,5 @@ class RssPluginConfig(Config): rss_feed_enabled = config_options.Type(bool, default=True) url_parameters = config_options.Optional(config_options.Type(dict)) use_git = config_options.Type(bool, default=True) + use_material_blog = config_options.Type(bool, default=True) use_material_social_cards = config_options.Type(bool, default=True) diff --git a/mkdocs_rss_plugin/integrations/theme_material_base.py b/mkdocs_rss_plugin/integrations/theme_material_base.py index ee01522..901abad 100644 --- a/mkdocs_rss_plugin/integrations/theme_material_base.py +++ b/mkdocs_rss_plugin/integrations/theme_material_base.py @@ -38,7 +38,7 @@ class IntegrationMaterialThemeBase: # attributes IS_THEME_MATERIAL: bool = False - IS_INSIDERS: bool = False + IS_INSIDERS: Optional[bool] = False def __init__(self, mkdocs_config: MkDocsConfig) -> None: """Integration instantiation. diff --git a/mkdocs_rss_plugin/plugin.py b/mkdocs_rss_plugin/plugin.py index 3f2a38b..a169ad4 100644 --- a/mkdocs_rss_plugin/plugin.py +++ b/mkdocs_rss_plugin/plugin.py @@ -31,6 +31,9 @@ DEFAULT_TEMPLATE_FOLDER, MKDOCS_LOGGER_NAME, ) +from mkdocs_rss_plugin.integrations.theme_material_blog_plugin import ( + IntegrationMaterialBlog, +) from mkdocs_rss_plugin.integrations.theme_material_social_plugin import ( IntegrationMaterialSocialCards, ) @@ -119,6 +122,12 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig: self.cache_dir.mkdir(parents=True, exist_ok=True) logger.debug(f"Caching HTTP requests to: {self.cache_dir.resolve()}") + # integrations - check if theme is Material and if blog are enabled + self.integration_material_blog = IntegrationMaterialBlog( + mkdocs_config=config, + switch_force=self.config.use_material_blog, + ) + # integrations - check if theme is Material and if social cards are enabled self.integration_material_social_cards = IntegrationMaterialSocialCards( mkdocs_config=config, @@ -129,6 +138,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig: self.util = Util( cache_dir=self.cache_dir, use_git=self.config.use_git, + integration_material_blog=self.integration_material_blog, integration_material_social_cards=self.integration_material_social_cards, mkdocs_command_is_on_serve=self.cmd_is_serve, ) diff --git a/mkdocs_rss_plugin/util.py b/mkdocs_rss_plugin/util.py index 1c14ab3..94b0705 100644 --- a/mkdocs_rss_plugin/util.py +++ b/mkdocs_rss_plugin/util.py @@ -41,6 +41,9 @@ REMOTE_REQUEST_HEADERS, ) from mkdocs_rss_plugin.git_manager.ci import CiHandler +from mkdocs_rss_plugin.integrations.theme_material_blog_plugin import ( + IntegrationMaterialBlog, +) from mkdocs_rss_plugin.integrations.theme_material_social_plugin import ( IntegrationMaterialSocialCards, ) @@ -67,6 +70,7 @@ class Util: def __init__( self, cache_dir: Path = DEFAULT_CACHE_FOLDER, + integration_material_blog: Optional[IntegrationMaterialBlog] = None, integration_material_social_cards: Optional[ IntegrationMaterialSocialCards ] = None, @@ -79,6 +83,8 @@ def __init__( Args: path (str, optional): path to the git repository to use. Defaults to ".". use_git (bool, optional): flag to use git under the hood or not. Defaults to True. + integration_material_blog (bool, optional): option to enable + integration with Blog plugin from Material theme. Defaults to True. integration_material_social_cards (bool, optional): option to enable integration with Social Cards plugin from Material theme. Defaults to True. """ @@ -128,6 +134,7 @@ def __init__( self.use_git = use_git # save integrations + self.material_blog = integration_material_blog self.social_cards = integration_material_social_cards # http/s session diff --git a/tests/fixtures/mkdocs_items_material_blog_enabled.yml b/tests/fixtures/mkdocs_items_material_blog_enabled.yml index d637ea6..df34928 100644 --- a/tests/fixtures/mkdocs_items_material_blog_enabled.yml +++ b/tests/fixtures/mkdocs_items_material_blog_enabled.yml @@ -5,7 +5,9 @@ site_url: https://guts.github.io/mkdocs-rss-plugin plugins: - blog: blog_dir: blog - - rss + authors_profiles: true + - rss: + use_material_blog: true theme: name: material From 344662dd56c063dc1d9fe1a23f6cd8e2c68768f4 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Mon, 2 Dec 2024 15:08:35 +0100 Subject: [PATCH 2/2] feature(integration): make the integration with Material Blog configurable through an option --- tests/test_config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index 9c4cd69..0420b3d 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -91,6 +91,7 @@ def test_plugin_config_defaults(self): "rss_feed_enabled": True, "url_parameters": None, "use_git": True, + "use_material_blog": True, "use_material_social_cards": True, } @@ -136,6 +137,7 @@ def test_plugin_config_image(self): "rss_feed_enabled": True, "url_parameters": None, "use_git": True, + "use_material_blog": True, "use_material_social_cards": True, }