Skip to content

Commit

Permalink
Do not append index with dirhtml (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 31, 2022
1 parent a2d9acc commit c47439c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Expand Up @@ -65,7 +65,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11-dev', 'pypy3.8']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.8']
sphinx-version: ['>=4,<5', '>=5,<6', '>=6a0,<7']
os: [windows-latest, macos-latest, ubuntu-latest]
exclude:
Expand Down
8 changes: 7 additions & 1 deletion sphinxext/opengraph/__init__.py
Expand Up @@ -91,7 +91,13 @@ def get_tags(
# url tag
# Get the URL of the specific page
if context["builder"] == "dirhtml":
page_url = urljoin(config["ogp_site_url"], context["pagename"] + "/")
if context["pagename"] == "index":
page_url = config["ogp_site_url"]
elif context["pagename"].endswith("/index"):
relative = context["pagename"].rsplit("/", 1)[0]
page_url = urljoin(config["ogp_site_url"], relative + "/")
else:
page_url = urljoin(config["ogp_site_url"], context["pagename"] + "/")
else:
page_url = urljoin(
config["ogp_site_url"], context["pagename"] + context["file_suffix"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_options.py
Expand Up @@ -68,7 +68,7 @@ def test_site_url(og_meta_tags):

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


@pytest.mark.sphinx("html", testroot="image")
Expand Down

0 comments on commit c47439c

Please sign in to comment.