Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dirhtml builder without ogp_site_url #84

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"