Skip to content

Commit 93564f4

Browse files
authored
improvement: if social card not found, try to retrieve length from remote URL (#225)
If the social card has been previously published, it works.
2 parents e505ce2 + 132f9a9 commit 93564f4

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

mkdocs_rss_plugin/util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,13 @@ def get_image(self, in_page: Page, base_url: str) -> Optional[Tuple[str, str, in
525525
if img_local_path.is_file():
526526
img_length = img_local_path.stat().st_size
527527
else:
528-
logger.debug(f"Social card: {img_local_path} still not exists.")
529-
img_length = None
528+
logger.debug(
529+
f"Social card: {img_local_path} still not exists. Trying to "
530+
f"retrieve length from remote image: {img_url}"
531+
"Note that would work only if the social card image has been "
532+
"published before)."
533+
)
534+
img_length = self.get_remote_image_length(image_url=img_url)
530535

531536
return (
532537
img_url,
@@ -575,7 +580,7 @@ def get_remote_image_length(
575580
http_method: str = "HEAD",
576581
attempt: int = 0,
577582
ssl_context: ssl.SSLContext = None,
578-
) -> int:
583+
) -> Optional[int]:
579584
"""Retrieve length for remote images (starting with 'http' \
580585
in meta.image or meta.illustration). \
581586
It tries to perform a HEAD request and get the length from the headers. \
@@ -591,7 +596,7 @@ def get_remote_image_length(
591596
:type ssl_context: ssl.SSLContext, optional
592597
593598
:return: image length as str or None
594-
:rtype: int
599+
:rtype: Optional[int]
595600
"""
596601
# prepare request
597602
req = request.Request(

0 commit comments

Comments
 (0)