fix: root internal links are now recognized properly
This commit is contained in:
parent
55df755596
commit
71e541aa5e
1 changed files with 15 additions and 5 deletions
|
@ -118,16 +118,26 @@ class ZonaLinkTreeprocessor(Treeprocessor):
|
|||
else:
|
||||
# treat as relative link and try to resolve
|
||||
resolved = (self.source.parent / cur).resolve()
|
||||
# check if the link is internal
|
||||
internal = same_file
|
||||
if not same_file:
|
||||
for suffix in {".md", ".html"}:
|
||||
if resolved.with_suffix(suffix).exists():
|
||||
internal = True
|
||||
resolved = resolved.with_suffix(suffix)
|
||||
break
|
||||
# only substitute if link points to an actual file
|
||||
# that isn't the self file
|
||||
if not same_file and resolved.exists():
|
||||
if not same_file and internal:
|
||||
item = self.item_map.get(resolved)
|
||||
if item:
|
||||
href = util.normalize_url(item.url)
|
||||
element.set("href", href)
|
||||
self.logger.debug(
|
||||
f"Link in file {self.source}: {_href} resolved to {href}"
|
||||
)
|
||||
# don't sub if it's already correct lol
|
||||
if _href != href:
|
||||
element.set("href", href)
|
||||
self.logger.debug(
|
||||
f"Link in file {self.source}: {_href} resolved to {href}"
|
||||
)
|
||||
else:
|
||||
self.logger.debug(
|
||||
f"Warning: resolved path {resolved} not found in item map"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue