diff --git a/README.md b/README.md index 5758c93..8d6a009 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,24 @@ Do note that this value also impacts `og_image_text` attribute, described in "[C *Default value*: `"og_image"` +## `SOCIAL_CARDS_INCLUDE_SERIES` + +If `True`, article series name will be included before title in text written on the card. + +Series name is defined by "Series" metadata key, as understood by [pelican-series plugin](https://github.com/pelican-plugins/series). + +Note that series name inclusion will work also when you do not have series plugin installed. Set this to `False` if your post titles already have series identifier. + +*Default value*: `False` + +## `SOCIAL_CARDS_SERIES_FORMAT` + +String template for article series name. + +Python `format()` method will be called on this string, with series name as the only parameter. `{}` will be replaced by series name. Use `{{` for literal `{` and `}}` for literal `}`. If you want to surround series name with curly brackets, set this to `{{{}}} `. + +*Default value*: `"{}: "` + ## `SOCIAL_CARDS_INCLUDE_SITEURL` If `True`, path to generated image (article / page `og_image` attribute) will include `SITEURL` setting value at the start. diff --git a/pelican/plugins/social_cards/cards_generator.py b/pelican/plugins/social_cards/cards_generator.py index 09e7898..7722145 100644 --- a/pelican/plugins/social_cards/cards_generator.py +++ b/pelican/plugins/social_cards/cards_generator.py @@ -86,6 +86,16 @@ def _get_article_title(self, article): title = title.replace("", "") title = html.unescape(title) + metadata_series = getattr(article, "series", None) + if metadata_series and PLUGIN_SETTINGS["INCLUDE_SERIES"]: + try: + series = metadata_series["name"] + except (TypeError, KeyError): + series = metadata_series + + series = PLUGIN_SETTINGS["SERIES_FORMAT"].format(series) + title = "{series}{title}".format(series=series, title=title) + title = wrapping_function( title.strip(), width=PLUGIN_SETTINGS["CHARS_PER_LINE"] ) diff --git a/pelican/plugins/social_cards/settings.py b/pelican/plugins/social_cards/settings.py index 78daaa6..c9010f0 100644 --- a/pelican/plugins/social_cards/settings.py +++ b/pelican/plugins/social_cards/settings.py @@ -25,6 +25,8 @@ "WRAPPING_FUNCTION": textwrap.wrap, "CHARS_PER_LINE": 30, "KEY_NAME": "og_image", + "INCLUDE_SERIES": False, + "SERIES_FORMAT": "{}: ", "INCLUDE_SITEURL": False, "INCLUDE_DRAFTS": False, "INCLUDE_HIDDEN": False,