fix: root internal links are now recognized properly

This commit is contained in:
Daniel Fichtinger 2025-07-12 00:34:14 -04:00
parent 55df755596
commit 71e541aa5e

View file

@ -118,12 +118,22 @@ class ZonaLinkTreeprocessor(Treeprocessor):
else: else:
# treat as relative link and try to resolve # treat as relative link and try to resolve
resolved = (self.source.parent / cur).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 # only substitute if link points to an actual file
# that isn't the self 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) item = self.item_map.get(resolved)
if item: if item:
href = util.normalize_url(item.url) href = util.normalize_url(item.url)
# don't sub if it's already correct lol
if _href != href:
element.set("href", href) element.set("href", href)
self.logger.debug( self.logger.debug(
f"Link in file {self.source}: {_href} resolved to {href}" f"Link in file {self.source}: {_href} resolved to {href}"