Skip to content

Commit 8bd8299

Browse files
committed
allow per-feed customisations of title and description
Adds new `title:` and `description` options to the plugin which will be used in the generated feeds. If these keys are not present, the default MkDocs site-wide `site_title:` and `site_description:` will be used.
1 parent a51c596 commit 8bd8299

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

docs/configuration.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,24 @@ At the end, into the RSS you will get:
367367

368368
----
369369

370+
### :material-subtitles: `description`: override site description { #description }
371+
372+
This option allows you to override the default MkDocs site description for the description tag in this RSS feed.
373+
This is useful if you have multiple instances of this plugin for multiple feeds. (For example, one feed
374+
for the blog, and a second for documentation updates.)
375+
376+
This setting is optional. If you do not include it, the default site description will be used.
377+
378+
```yaml
379+
plugins:
380+
- rss:
381+
description: The best blog from the best site
382+
```
383+
384+
Default: Use the default MkDocs `site_description:`.
385+
386+
----
387+
370388
### :material-alphabet-latin: `feeds_filenames`: customize the output feed URL { #feeds_filenames }
371389

372390
> Since version 1.13.0.
@@ -478,6 +496,24 @@ Default: `False`.
478496

479497
----
480498

499+
### :material-format-title: `title`: override site title { #title }
500+
501+
This option allows you to override the default MkDocs site title for the title tag in this RSS feed.
502+
This is useful if you have multiple instances of this plugin for multiple feeds. (For example, one feed
503+
for the blog, and a second for documentation updates.)
504+
505+
This setting is optional. If you do not include it, the default site title will be used.
506+
507+
```yaml
508+
plugins:
509+
- rss:
510+
title: My awesome blog feed
511+
```
512+
513+
Default: Use the default MkDocs `site_title:`.
514+
515+
----
516+
481517
### :material-track-light: `url_parameters`: additional URL parameters { #url_parameters }
482518

483519
This option allows you to add parameters to the URLs of the RSS feed items. It works as a dictionary of keys/values that is passed to [Python *urllib.parse.urlencode*](https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode).

mkdocs_rss_plugin/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class RssPluginConfig(Config):
4444
)
4545
comments_path = config_options.Optional(config_options.Type(str))
4646
date_from_meta = config_options.SubConfig(_DateFromMeta)
47+
description = config_options.Type(str, default="")
4748
enabled = config_options.Type(bool, default=True)
4849
feed_ttl = config_options.Type(int, default=1440)
4950
feeds_filenames = config_options.SubConfig(_FeedsFilenamesConfig)
@@ -53,6 +54,7 @@ class RssPluginConfig(Config):
5354
match_path = config_options.Type(str, default=".*")
5455
pretty_print = config_options.Type(bool, default=False)
5556
rss_feed_enabled = config_options.Type(bool, default=True)
57+
title = config_options.Type(str, default="")
5658
url_parameters = config_options.Optional(config_options.Type(dict))
5759
use_git = config_options.Type(bool, default=True)
5860
use_material_social_cards = config_options.Type(bool, default=True)

mkdocs_rss_plugin/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,16 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
115115
"author": config.site_author or None,
116116
"buildDate": formatdate(get_build_timestamp()),
117117
"copyright": config.copyright,
118-
"description": config.site_description,
118+
"description": self.config['description'] if self.config['description'] \
119+
else config['site_description'],
119120
"entries": [],
120121
"generator": f"{__title__} - v{__version__}",
121122
"html_url": self.util.get_site_url(mkdocs_config=config),
122123
"language": self.util.guess_locale(mkdocs_config=config),
123124
"pubDate": formatdate(get_build_timestamp()),
124125
"repo_url": config.repo_url,
125-
"title": config.site_name,
126+
"title": self.config['title'] if self.config['title'] \
127+
else config['site_name'],
126128
"ttl": self.config.feed_ttl,
127129
}
128130

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
site_name: Test RSS Plugin with custom titles and descriptions
2+
site_description: Test RSS Plugin with customized descriptions
3+
site_url: https://guts.github.io/mkdocs-rss-plugin
4+
5+
plugins:
6+
- rss:
7+
title: My custom RSS title
8+
description: My custom RSS description
9+
10+
theme:
11+
name: mkdocs

tests/test_build.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,25 @@ def test_simple_build_pretty_print_disabled(self):
657657
with Path(Path(tmpdirname) / OUTPUT_RSS_FEED_UPDATED).open("r") as f:
658658
self.assertEqual(len(f.readlines()), 1)
659659

660+
def test_simple_build_custome_title_description(self):
661+
with tempfile.TemporaryDirectory() as tmpdirname:
662+
cli_result = self.build_docs_setup(
663+
testproject_path="docs",
664+
mkdocs_yml_filepath=Path("tests/fixtures/mkdocs_custom_title_description.yml"),
665+
output_path=tmpdirname,
666+
)
667+
if cli_result.exception is not None:
668+
e = cli_result.exception
669+
logger.debug(format_exception(type(e), e, e.__traceback__))
670+
671+
self.assertEqual(cli_result.exit_code, 0)
672+
self.assertIsNone(cli_result.exception)
673+
674+
# created items
675+
feed_parsed = feedparser.parse(Path(tmpdirname) / OUTPUT_RSS_FEED_CREATED)
676+
self.assertEqual(feed_parsed.feed.title, "My custom RSS title")
677+
self.assertEqual(feed_parsed.feed.description, "My custom RSS description")
678+
660679
def test_rss_feed_validation(self):
661680
with tempfile.TemporaryDirectory() as tmpdirname:
662681
cli_result = self.build_docs_setup(

tests/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def test_plugin_config_defaults(self):
7070
"default_time": datetime.min.strftime("%H:%M"),
7171
"default_timezone": "UTC",
7272
},
73+
"description": "",
7374
"enabled": True,
7475
"feed_ttl": 1440,
7576
"image": None,
@@ -84,6 +85,7 @@ def test_plugin_config_defaults(self):
8485
},
8586
"pretty_print": False,
8687
"rss_feed_enabled": True,
88+
"title": "",
8789
"url_parameters": None,
8890
"use_git": True,
8991
"use_material_social_cards": True,
@@ -112,6 +114,7 @@ def test_plugin_config_image(self):
112114
"default_time": datetime.min.strftime("%H:%M"),
113115
"default_timezone": "UTC",
114116
},
117+
"description": "",
115118
"enabled": True,
116119
"feed_ttl": 1440,
117120
"image": self.feed_image,
@@ -126,6 +129,7 @@ def test_plugin_config_image(self):
126129
},
127130
"pretty_print": False,
128131
"rss_feed_enabled": True,
132+
"title": "",
129133
"url_parameters": None,
130134
"use_git": True,
131135
"use_material_social_cards": True,

0 commit comments

Comments
 (0)