Skip to content

Commit c47439c

Browse files
authored
Do not append index with dirhtml (#78)
1 parent a2d9acc commit c47439c

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
strategy:
6666
fail-fast: false
6767
matrix:
68-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11-dev', 'pypy3.8']
68+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.8']
6969
sphinx-version: ['>=4,<5', '>=5,<6', '>=6a0,<7']
7070
os: [windows-latest, macos-latest, ubuntu-latest]
7171
exclude:

sphinxext/opengraph/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ def get_tags(
9191
# url tag
9292
# Get the URL of the specific page
9393
if context["builder"] == "dirhtml":
94-
page_url = urljoin(config["ogp_site_url"], context["pagename"] + "/")
94+
if context["pagename"] == "index":
95+
page_url = config["ogp_site_url"]
96+
elif context["pagename"].endswith("/index"):
97+
relative = context["pagename"].rsplit("/", 1)[0]
98+
page_url = urljoin(config["ogp_site_url"], relative + "/")
99+
else:
100+
page_url = urljoin(config["ogp_site_url"], context["pagename"] + "/")
95101
else:
96102
page_url = urljoin(
97103
config["ogp_site_url"], context["pagename"] + context["file_suffix"]

tests/test_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_site_url(og_meta_tags):
6868

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

7373

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

0 commit comments

Comments
 (0)