-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream Sphinx doesn't construct canonical links correctly for the DirectoryHTMLBuilder. When I introduced #650, it included a bug for `index.html` pages. This PR adds a proper fix with tests this time to make sure that canonical links are what they should be. This PR is a follow up of #1258 and reverts the change in `layout.html`. Checking the canonical link shouldn't be done in the template. It's reported here: [#9730](sphinx-doc/sphinx#9730)
- Loading branch information
Showing
9 changed files
with
171 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Changelog | ||
|
||
## 4.0.3 | ||
|
||
- Fix canonical links | ||
|
||
## 4.0.2 | ||
|
||
- Restore missing logo (#1214) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ nox==2022.11.21 | |
nox-poetry==1.0.2 | ||
pip==23.0.1 | ||
pipx==1.2.0 | ||
poetry==1.4.1 | ||
poetry==1.4.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "sphinxawesome-theme" | ||
version = "4.0.2" | ||
version = "4.0.3" | ||
description = "An awesome theme for the Sphinx documentation generator" | ||
readme = "README.md" | ||
authors = ["Kai Welke <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Test the construction of canonical links.""" | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
import pytest | ||
from sphinx.application import Sphinx | ||
|
||
from .util import parse_html | ||
|
||
|
||
@pytest.mark.sphinx( | ||
"html", | ||
confoverrides={ | ||
"extensions": ["sphinxawesome_theme"], | ||
"html_theme": "sphinxawesome_theme", | ||
}, | ||
) | ||
def test_no_canonical_links_in_html(app: Sphinx) -> None: | ||
"""It doesn't add canonical links by default.""" | ||
app.build() | ||
assert os.path.exists(Path(app.outdir) / "index.html") | ||
tree = parse_html(Path(app.outdir) / "index.html") | ||
link = tree.select("[rel=canonical]") | ||
assert len(link) == 0 | ||
|
||
|
||
@pytest.mark.sphinx( | ||
"dirhtml", | ||
confoverrides={ | ||
"extensions": ["sphinxawesome_theme"], | ||
"html_theme": "sphinxawesome_theme", | ||
}, | ||
) | ||
def test_no_canonical_links_in_dirhtml(app: Sphinx) -> None: | ||
"""It doesn't add canonical links by default.""" | ||
app.build() | ||
assert os.path.exists(Path(app.outdir) / "index.html") | ||
tree = parse_html(Path(app.outdir) / "index.html") | ||
link = tree.select("[rel=canonical]") | ||
assert len(link) == 0 | ||
|
||
|
||
@pytest.mark.sphinx( | ||
"html", | ||
confoverrides={ | ||
"extensions": ["sphinxawesome_theme"], | ||
"html_theme": "sphinxawesome_theme", | ||
"html_baseurl": "https://test.org", | ||
}, | ||
) | ||
def test_canonical_links_in_html(app: Sphinx) -> None: | ||
"""It adds the correct canonical link for the HTML builder.""" | ||
app.build() | ||
assert os.path.exists(Path(app.outdir) / "index.html") | ||
tree = parse_html(Path(app.outdir) / "index.html") | ||
link = tree.select("[rel=canonical]") | ||
assert len(link) == 1 | ||
assert link[0]["href"] == "https://test.org/index.html" | ||
|
||
|
||
@pytest.mark.sphinx( | ||
"dirhtml", | ||
confoverrides={ | ||
"extensions": ["sphinxawesome_theme"], | ||
"html_theme": "sphinxawesome_theme", | ||
"html_baseurl": "https://test.org", | ||
}, | ||
) | ||
def test_canonical_links_in_dirhtml(app: Sphinx) -> None: | ||
"""It adds the correct canonical link for the DirectoryHTML builder.""" | ||
app.build() | ||
assert os.path.exists(Path(app.outdir) / "index.html") | ||
tree = parse_html(Path(app.outdir) / "index.html") | ||
link = tree.select("[rel=canonical]") | ||
assert len(link) == 1 | ||
assert link[0]["href"] == "https://test.org/" |