Skip to content

Commit 80279c4

Browse files
committed
Change to always use canonical URL when ogp_site_url is unconfigured
1 parent edc4662 commit 80279c4

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

sphinxext/opengraph/__init__.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import docutils.nodes as nodes
66
from sphinx.application import Sphinx
7+
from sphinx.errors import ConfigError
78

89
from .descriptionparser import get_description
910
from .titleparser import get_title
@@ -67,26 +68,15 @@ def get_tags(
6768
# type tag
6869
tags["og:type"] = config["ogp_type"]
6970

70-
if os.getenv("READTHEDOCS") and config["ogp_site_url"] is None:
71-
# readthedocs uses html_baseurl for sphinx > 1.8
72-
parse_result = urlparse(config["html_baseurl"])
73-
71+
# url tag
72+
# Get the canonical URL if ogp_site_url is not configured
73+
if config["ogp_site_url"] is None:
74+
# we require that either ogp_site_url or html_baseurl be configured
7475
if config["html_baseurl"] is None:
75-
raise EnvironmentError("ReadTheDocs did not provide a valid canonical URL!")
76-
77-
# Grab root url from canonical url
78-
config["ogp_site_url"] = urlunparse(
79-
(
80-
parse_result.scheme,
81-
parse_result.netloc,
82-
parse_result.path,
83-
"",
84-
"",
85-
"",
86-
)
87-
)
76+
raise ConfigError("A URL has not been configured and is required as per the OpenGraph Specification!")
77+
78+
config["ogp_site_url"] = config["html_baseurl"]
8879

89-
# url tag
9080
# Get the URL of the specific page
9181
if context["builder"] == "dirhtml":
9282
page_url = urljoin(config["ogp_site_url"], context["pagename"] + "/")

0 commit comments

Comments
 (0)