Skip to content

Commit

Permalink
feature(integration): make the integration with Material Blog configu…
Browse files Browse the repository at this point in the history
…rable through an option (#339)

Related to #250
  • Loading branch information
Guts authored Dec 2, 2024
2 parents 7075e93 + 344662d commit 9e5f2b3
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ plugins:
utm_medium: "RSS"
utm_campaign: "feed-syndication"
use_git: true
use_material_blog: true
use_material_social_cards: true
```
Expand Down
10 changes: 10 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions mkdocs_rss_plugin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion mkdocs_rss_plugin/integrations/theme_material_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions mkdocs_rss_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down
7 changes: 7 additions & 0 deletions mkdocs_rss_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/mkdocs_items_material_blog_enabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}

Expand Down

0 comments on commit 9e5f2b3

Please sign in to comment.