Skip to content

Commit

Permalink
Allow dirhtml builder without ogp_site_url (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdarst committed Nov 22, 2022
1 parent 82c3eb4 commit fc41303
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sphinxext/opengraph/__init__.py
Expand Up @@ -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"])

Expand Down Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_options.py
Expand Up @@ -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"

0 comments on commit fc41303

Please sign in to comment.