diff --git a/Doc/Makefile b/Doc/Makefile
index 53af6aca659cef..710f1f6466c425 100644
--- a/Doc/Makefile
+++ b/Doc/Makefile
@@ -205,6 +205,7 @@ dist-html:
find dist -name 'python-$(DISTVERSION)-docs-html*' -exec rm -rf {} \;
$(MAKE) html
cp -pPR build/html dist/python-$(DISTVERSION)-docs-html
+ rm -rf dist/python-$(DISTVERSION)-docs-html/_images/social_previews/
tar -C dist -cf dist/python-$(DISTVERSION)-docs-html.tar python-$(DISTVERSION)-docs-html
bzip2 -9 -k dist/python-$(DISTVERSION)-docs-html.tar
(cd dist; zip -q -r -9 python-$(DISTVERSION)-docs-html.zip python-$(DISTVERSION)-docs-html)
diff --git a/Doc/conf.py b/Doc/conf.py
index b4a924b7bf0857..ed64708487f7e3 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -623,9 +623,17 @@
ogp_site_url = 'https://docs.python.org/3/'
ogp_site_name = 'Python documentation'
-ogp_image = '_static/og-image.png'
+ogp_social_cards = { # Used when matplotlib is installed
+ 'image': '_static/og-image.png',
+ 'line_color': '#3776ab',
+}
ogp_custom_meta_tags = [
- '',
- '',
'',
]
+if 'create-social-cards' not in tags: # noqa: F821
+ # Define a static preview image when not creating social cards
+ ogp_image = '_static/og-image.png'
+ ogp_custom_meta_tags += [
+ '',
+ '',
+ ]