Skip to content

Commit 8ee2ff6

Browse files
committed
Remove any support for relative paths with field lists and add a note
1 parent c3ab424 commit 8ee2ff6

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Users hosting documentation on Read The Docs *do not* need to set any of the fol
2828
* `ogp_site_name`
2929
* This is not required. Name of the site. This is displayed above the title.
3030
* `ogp_image`
31-
* This is not required. Link to image to show.
31+
* This is not required. Link to image to show. Note that all relative paths are converted to be relative to the root of the html output.
3232
* `ogp_image_alt`
3333
* This is not required. Alt text for image. Defaults to using `ogp_site_name` or the document's title as alt text, if available. Set to `False` if you want to turn off alt text completely.
3434
* `ogp_use_first_image`
@@ -78,7 +78,7 @@ These are some overrides that can be used, you can actually override any tag and
7878
* `:og:type:`
7979
* Override the type of the page, for the list of available types take a look at https://ogp.me/#types.
8080
* `:ogp:image:`
81-
* Set the image for the page.
81+
* Set the image for the page. Note: Relative file paths are ***not*** currently supported when using field lists.
8282
* `:ogp:image:alt:`
8383
* Sets the alt text. Will be ignored if there is no image set.
8484

@@ -92,12 +92,16 @@ Remember that the fields **must** be placed at the very start of the file. You c
9292
9393
Page contents
9494
=============
95+
```
9596

9697
### Arbitrary Tags
9798
Additionally, you can use field lists to add any arbitrary OpenGraph tag not supported by the extension. The syntax for arbitrary tags is the same with `:og:tag: content`. For Example:
9899

100+
Note: Relative file paths are ***not*** currently supported for images, videos and audio when using field lists.
101+
99102
```rst
100103
:og:video: http://example.org/video.mp4
101104
102105
Page contents
103106
=============
107+
```

sphinxext/opengraph/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ def get_tags(
113113
image_url = config["ogp_image"]
114114
ogp_use_first_image = config["ogp_use_first_image"]
115115
ogp_image_alt = fields.get("og:image:alt", config["ogp_image_alt"])
116+
117+
if image_url:
118+
image_url_parsed = urlparse(image_url)
119+
if not image_url_parsed.scheme:
120+
# Relative image path detected. Make absolute.
121+
image_url = urljoin(config["ogp_site_url"], image_url_parsed.path)
122+
116123
fields.pop("og:image:alt", None)
117124

118125
if ogp_use_first_image:
@@ -125,10 +132,6 @@ def get_tags(
125132
ogp_image_alt = first_image.get("alt", None)
126133

127134
if image_url:
128-
image_url_parsed = urlparse(image_url)
129-
if not image_url_parsed.scheme:
130-
# Relative image path detected. Make absolute.
131-
image_url = urljoin(config["ogp_site_url"], image_url_parsed.path)
132135
tags["og:image"] = image_url
133136

134137
# Add image alt text (either provided by config or from site_name)

0 commit comments

Comments
 (0)