@@ -41,7 +41,9 @@ def _set_description_line_width():
41
41
return 1000
42
42
43
43
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
+ ):
45
47
"""Create a social preview card according to page metadata.
46
48
47
49
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
51
53
52
54
# Add a hash to the image path based on metadata to bust caches
53
55
# 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 ]
55
59
56
60
# Define the file path we'll use for this image
57
61
path_images_relative = Path ("_images/social_previews" )
@@ -83,7 +87,9 @@ def create_social_card(app, config_social, site_name, page_title, description, u
83
87
"image_mini"
84
88
)
85
89
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
+ )
87
93
88
94
# These are passed directly from the user configuration to our plotting function
89
95
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
96
102
plt_objects = app .env .ogp_social_card_plt_objects
97
103
else :
98
104
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
+ )
100
114
app .env .ogp_social_card_plt_objects = plt_objects
101
115
102
116
# Path relative to build folder will be what we use for linking the URL
103
117
path_relative_to_build = path_images_relative / filename_image
104
118
return path_relative_to_build
105
119
106
120
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
+ ):
108
130
"""Render a social preview card with Matplotlib and write to disk."""
109
131
# If objects is None it means this is the first time plotting.
110
132
# Create the figure objects and return them so that we re-use them later.
111
133
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 )
113
141
else :
114
142
fig , txt_site_title , txt_page_title , txt_description , txt_url = plt_objects
115
143
0 commit comments