diff --git a/sphinxext/opengraph/__init__.py b/sphinxext/opengraph/__init__.py index a4bc48d..c02ffd6 100644 --- a/sphinxext/opengraph/__init__.py +++ b/sphinxext/opengraph/__init__.py @@ -69,7 +69,7 @@ def get_tags( # type tag tags["og:type"] = config["ogp_type"] - if os.getenv("READTHEDOCS") and config["ogp_site_url"] is None: + if os.getenv("READTHEDOCS") and not config["ogp_site_url"]: # readthedocs uses html_baseurl for sphinx > 1.8 parse_result = urlparse(config["html_baseurl"]) @@ -193,7 +193,9 @@ def html_page_context( def setup(app: Sphinx) -> Dict[str, Any]: - app.add_config_value("ogp_site_url", None, "html") + # ogp_site_url="" allows relative by default, even though it's not + # officially supported by OGP. + app.add_config_value("ogp_site_url", "", "html") app.add_config_value("ogp_description_length", DEFAULT_DESCRIPTION_LENGTH, "html") app.add_config_value("ogp_image", None, "html") app.add_config_value("ogp_image_alt", None, "html") diff --git a/tests/test_options.py b/tests/test_options.py index b814ca7..c61f9a1 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -279,3 +279,15 @@ def test_rtd_invalid(app: Sphinx, monkeypatch): with pytest.raises(Exception): app.build() + + +# Test no breakage with no configuration +@pytest.mark.sphinx("html", testroot="rtd-default") +def test_no_configuration_html(og_meta_tags): + assert get_tag_content(og_meta_tags, "type") == "website" + + +# Test no breakage with no configuration +@pytest.mark.sphinx("dirhtml", testroot="rtd-default") +def test_no_configuration_dirhtml(og_meta_tags): + assert get_tag_content(og_meta_tags, "type") == "website"