Skip to content

Commit

Permalink
Add support for series plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mirekdlugosz committed Feb 18, 2024
1 parent 1b69fac commit 9a89b8a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions pelican/plugins/social_cards/cards_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ def _get_article_title(self, article):
title = title.replace("</span>", "")
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"]
)
Expand Down
2 changes: 2 additions & 0 deletions pelican/plugins/social_cards/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9a89b8a

Please sign in to comment.