Skip to content

Commit 8029089

Browse files
committed
Fix relative first_image usages when ogp_image is defined in the config
1 parent 9dbff79 commit 8029089

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sphinxext/opengraph/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def get_tags(
119119

120120
fields.pop("og:image:alt", None)
121121

122+
first_image = None
122123
if ogp_use_first_image:
123124
first_image = doctree.next_node(nodes.image)
124125
if (
@@ -134,12 +135,12 @@ def get_tags(
134135
image_url_parsed = urlparse(image_url)
135136
if not image_url_parsed.scheme:
136137
# Relative image path detected, relative to the source. Make absolute.
137-
if config["ogp_image"]:
138+
if first_image:
139+
root = page_url
140+
else:
138141
# ogp_image is defined as being relative to the site root.
139142
# This workaround is to keep that functionality from breaking.
140143
root = config["ogp_site_url"]
141-
else:
142-
root = page_url
143144

144145
image_url = urljoin(root, image_url_parsed.path)
145146
tags["og:image"] = image_url

0 commit comments

Comments
 (0)