Skip to content

Commit ff69d8e

Browse files
committed
Run black
1 parent f6f1e95 commit ff69d8e

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

sphinxext/opengraph/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def get_tags(
125125
image_url = fields["og:image"]
126126
ogp_use_first_image = False
127127
ogp_image_alt = fields.get("og:image:alt")
128-
fields.pop("og:image", None)
128+
fields.pop("og:image", None)
129129
else:
130130
image_url = config["ogp_image"]
131131
ogp_use_first_image = config["ogp_use_first_image"]
@@ -139,7 +139,10 @@ def get_tags(
139139
config_social.update(social_card_user_options)
140140

141141
# This will only be False if the user explicitly sets it
142-
if not (image_url or ogp_use_first_image) and config_social.get("enable") is not False:
142+
if (
143+
not (image_url or ogp_use_first_image)
144+
and config_social.get("enable") is not False
145+
):
143146
# Description
144147
description_max_length = config_social.get(
145148
"description_max_length", DEFAULT_DESCRIPTION_LENGTH_SOCIAL_CARDS - 3
@@ -167,7 +170,7 @@ def get_tags(
167170
pagetitle,
168171
description,
169172
url_text,
170-
context["pagename"]
173+
context["pagename"],
171174
)
172175
ogp_use_first_image = False
173176

sphinxext/opengraph/socialcards.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def _set_description_line_width():
4141
return 1000
4242

4343

44-
def create_social_card(app, config_social, site_name, page_title, description, url_text, page_path):
44+
def create_social_card(
45+
app, config_social, site_name, page_title, description, url_text, page_path
46+
):
4547
"""Create a social preview card according to page metadata.
4648
4749
This uses page metadata and calls a render function to generate the image.
@@ -51,7 +53,9 @@ def create_social_card(app, config_social, site_name, page_title, description, u
5153

5254
# Add a hash to the image path based on metadata to bust caches
5355
# ref: https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/troubleshooting-cards#refreshing_images # noqa
54-
hash = hashlib.sha1((site_name + page_title + description + str(config_social)).encode()).hexdigest()[:8]
56+
hash = hashlib.sha1(
57+
(site_name + page_title + description + str(config_social)).encode()
58+
).hexdigest()[:8]
5559

5660
# Define the file path we'll use for this image
5761
path_images_relative = Path("_images/social_previews")
@@ -83,7 +87,9 @@ def create_social_card(app, config_social, site_name, page_title, description, u
8387
"image_mini"
8488
)
8589
else:
86-
kwargs_fig["image_mini"] = Path(__file__).parent / "_static/sphinx-logo-shadow.png"
90+
kwargs_fig["image_mini"] = (
91+
Path(__file__).parent / "_static/sphinx-logo-shadow.png"
92+
)
8793

8894
# These are passed directly from the user configuration to our plotting function
8995
pass_through_config = ["text_color", "line_color", "background_color", "font"]
@@ -96,20 +102,42 @@ def create_social_card(app, config_social, site_name, page_title, description, u
96102
plt_objects = app.env.ogp_social_card_plt_objects
97103
else:
98104
plt_objects = None
99-
plt_objects = render_social_card(path_image, site_name, page_title, description, url_text, plt_objects, kwargs_fig)
105+
plt_objects = render_social_card(
106+
path_image,
107+
site_name,
108+
page_title,
109+
description,
110+
url_text,
111+
plt_objects,
112+
kwargs_fig,
113+
)
100114
app.env.ogp_social_card_plt_objects = plt_objects
101115

102116
# Path relative to build folder will be what we use for linking the URL
103117
path_relative_to_build = path_images_relative / filename_image
104118
return path_relative_to_build
105119

106120

107-
def render_social_card(path, site_title=None, page_title=None, description=None, siteurl=None, plt_objects=None, kwargs_fig=None):
121+
def render_social_card(
122+
path,
123+
site_title=None,
124+
page_title=None,
125+
description=None,
126+
siteurl=None,
127+
plt_objects=None,
128+
kwargs_fig=None,
129+
):
108130
"""Render a social preview card with Matplotlib and write to disk."""
109131
# If objects is None it means this is the first time plotting.
110132
# Create the figure objects and return them so that we re-use them later.
111133
if plt_objects is None:
112-
fig, txt_site_title, txt_page_title, txt_description, txt_url = create_social_card_objects(**kwargs_fig)
134+
(
135+
fig,
136+
txt_site_title,
137+
txt_page_title,
138+
txt_description,
139+
txt_url,
140+
) = create_social_card_objects(**kwargs_fig)
113141
else:
114142
fig, txt_site_title, txt_page_title, txt_description, txt_url = plt_objects
115143

0 commit comments

Comments
 (0)