Skip to content

Commit fc41303

Browse files
authored
Allow dirhtml builder without ogp_site_url (#84)
1 parent 82c3eb4 commit fc41303

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

sphinxext/opengraph/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def get_tags(
6969
# type tag
7070
tags["og:type"] = config["ogp_type"]
7171

72-
if os.getenv("READTHEDOCS") and config["ogp_site_url"] is None:
72+
if os.getenv("READTHEDOCS") and not config["ogp_site_url"]:
7373
# readthedocs uses html_baseurl for sphinx > 1.8
7474
parse_result = urlparse(config["html_baseurl"])
7575

@@ -193,7 +193,9 @@ def html_page_context(
193193

194194

195195
def setup(app: Sphinx) -> Dict[str, Any]:
196-
app.add_config_value("ogp_site_url", None, "html")
196+
# ogp_site_url="" allows relative by default, even though it's not
197+
# officially supported by OGP.
198+
app.add_config_value("ogp_site_url", "", "html")
197199
app.add_config_value("ogp_description_length", DEFAULT_DESCRIPTION_LENGTH, "html")
198200
app.add_config_value("ogp_image", None, "html")
199201
app.add_config_value("ogp_image_alt", None, "html")

tests/test_options.py

+12
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,15 @@ def test_rtd_invalid(app: Sphinx, monkeypatch):
279279

280280
with pytest.raises(Exception):
281281
app.build()
282+
283+
284+
# Test no breakage with no configuration
285+
@pytest.mark.sphinx("html", testroot="rtd-default")
286+
def test_no_configuration_html(og_meta_tags):
287+
assert get_tag_content(og_meta_tags, "type") == "website"
288+
289+
290+
# Test no breakage with no configuration
291+
@pytest.mark.sphinx("dirhtml", testroot="rtd-default")
292+
def test_no_configuration_dirhtml(og_meta_tags):
293+
assert get_tag_content(og_meta_tags, "type") == "website"

0 commit comments

Comments
 (0)