Skip to content

Commit edc4662

Browse files
authored
Fix og:url for "dirhtml" builder (#54)
* 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>
1 parent d5db5c4 commit edc4662

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sphinxext/opengraph/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ def get_tags(
8888

8989
# url tag
9090
# Get the URL of the specific page
91-
page_url = urljoin(
92-
config["ogp_site_url"], context["pagename"] + context["file_suffix"]
93-
)
91+
if context["builder"] == "dirhtml":
92+
page_url = urljoin(config["ogp_site_url"], context["pagename"] + "/")
93+
else:
94+
page_url = urljoin(
95+
config["ogp_site_url"], context["pagename"] + context["file_suffix"]
96+
)
9497
tags["og:url"] = page_url
9598

9699
# site name tag

tests/test_options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ def test_site_url(og_meta_tags):
3232
assert get_tag_content(og_meta_tags, "url") == "http://example.org/index.html"
3333

3434

35+
@pytest.mark.sphinx("dirhtml", testroot="simple")
36+
def test_dirhtml_url(og_meta_tags):
37+
assert get_tag_content(og_meta_tags, "url") == "http://example.org/index/"
38+
39+
3540
@pytest.mark.sphinx("html", testroot="image")
3641
def test_image(og_meta_tags):
3742
assert get_tag_content(og_meta_tags, "image") == "http://example.org/image.png"

0 commit comments

Comments
 (0)