Skip to content

Commit 1a0e01d

Browse files
committed
Resolve local relative links to html_extra_path
Signed-off-by: Filipe Laíns <[email protected]>
1 parent 5cad368 commit 1a0e01d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pug_sphinx_extensions/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import pathlib
23
import urllib
34

45
import sphinx.application
@@ -52,9 +53,12 @@ def resolve_local_html_link(app: sphinx.application.Sphinx, url_path: str) -> st
5253
def rewrite_local_uri(app: sphinx.application.Sphinx, uri: str) -> str:
5354
"""Replace remote URIs targeting https://packaging.python.org/en/latest/...
5455
with local ones, so that local changes are taken into account by linkcheck.
56+
57+
Additionally, resolve local relative links to html_extra_path.
5558
"""
5659
local_uri = uri
5760
parsed = urllib.parse.urlparse(uri)
61+
# Links to https://packaging.python.org/en/latest/...
5862
if parsed.hostname == DOMAIN and parsed.path.startswith("/en/latest/"):
5963
document = parsed.path.removeprefix("/en/latest/")
6064
local_uri = resolve_local_html_link(app, document)
@@ -64,6 +68,12 @@ def rewrite_local_uri(app: sphinx.application.Sphinx, uri: str) -> str:
6468
"into account (pass -vv for more info)"
6569
)
6670
logger.debug(f"Replacing linkcheck URL {uri!r} with {local_uri!r}")
71+
# Local relative links
72+
if not parsed.scheme and not parsed.netloc and parsed.path:
73+
full_path = pathlib.Path(app.env.docname).parent / parsed.path
74+
local_uri = resolve_local_html_link(app, os.fspath(full_path))
75+
if local_uri != uri:
76+
logger.verbose(f"Local linkcheck URL {uri!r} resolved as {local_uri!r}")
6777
return local_uri
6878

6979

0 commit comments

Comments
 (0)