Skip to content

Commit

Permalink
Fix og:url for "dirhtml" builder (#54)
Browse files Browse the repository at this point in the history
* fix og:url for "dirhtml" builder

The "dirhtml" builder correctly uses ".html" as file suffix,
but the file suffix should not be part of the URL.
We want ".../file_name/" as URL in this case, not
".../file_name.html".

Signed-off-by: Ruth Fuchss <ruth.fuchss@canonical.com>

* add dirhtml test case

Signed-off-by: Ruth Fuchss <ruth.fuchss@canonical.com>
  • Loading branch information
ru-fu authored Feb 23, 2022
1 parent d5db5c4 commit edc4662
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sphinxext/opengraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ def get_tags(

# url tag
# Get the URL of the specific page
page_url = urljoin(
config["ogp_site_url"], context["pagename"] + context["file_suffix"]
)
if context["builder"] == "dirhtml":
page_url = urljoin(config["ogp_site_url"], context["pagename"] + "/")
else:
page_url = urljoin(
config["ogp_site_url"], context["pagename"] + context["file_suffix"]
)
tags["og:url"] = page_url

# site name tag
Expand Down
5 changes: 5 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def test_site_url(og_meta_tags):
assert get_tag_content(og_meta_tags, "url") == "http://example.org/index.html"


@pytest.mark.sphinx("dirhtml", testroot="simple")
def test_dirhtml_url(og_meta_tags):
assert get_tag_content(og_meta_tags, "url") == "http://example.org/index/"


@pytest.mark.sphinx("html", testroot="image")
def test_image(og_meta_tags):
assert get_tag_content(og_meta_tags, "image") == "http://example.org/image.png"
Expand Down

0 comments on commit edc4662

Please sign in to comment.