This commit is contained in:
Peter Murray 2025-07-22 15:41:58 -04:00 committed by GitHub
commit ef8d405623
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

3
RELEASE.md Normal file
View file

@ -0,0 +1,3 @@
Release type: minor
Allow extensionless internal links

View file

@ -13,7 +13,6 @@ try:
except ModuleNotFoundError:
from backports.zoneinfo import ZoneInfo
from pelican.plugins import signals
from pelican.settings import DEFAULT_CONFIG, Settings
@ -281,7 +280,9 @@ class Content:
# XXX Put this in a different location.
if what in {"filename", "static", "attach"}:
def _get_linked_content(key: str, url: ParseResult) -> Optional[Content]:
def _get_linked_content(
key: str, url: ParseResult, extension: Optional[str] = None
) -> Optional[Content]:
nonlocal value
def _find_path(path: str) -> Optional[Content]:
@ -294,13 +295,15 @@ class Content:
)
return self._context[key].get(path, None)
url_path = url.path if not extension else f"{url.path}.{extension}"
# try path
result = _find_path(url.path)
result = _find_path(url_path)
if result is not None:
return result
# try unquoted path
result = _find_path(unquote(url.path))
result = _find_path(unquote(url_path))
if result is not None:
return result
@ -330,7 +333,13 @@ class Content:
else:
key = "static_content"
linked_content = _get_linked_content(key, value)
# Where do we find a comprehensive list of Reader extensions?
reader_ext = ["md", "markdown"]
extensions = [None] + reader_ext
for extension in extensions:
if linked_content := _get_linked_content(key, value, extension):
break
if linked_content:
if what == "attach":
linked_content.attach_to(self) # type: ignore