Skip to content

Commit 5e78405

Browse files
committed
fix(http): disable remote images fetching on Mkdocs serve
1 parent f5a9746 commit 5e78405

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

mkdocs_rss_plugin/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
123123
cache_dir=self.cache_dir,
124124
use_git=self.config.use_git,
125125
integration_material_social_cards=self.integration_material_social_cards,
126+
mkdocs_command_is_on_serve=self.cmd_is_serve,
126127
)
127128

128129
# check template dirs

mkdocs_rss_plugin/util.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ class Util:
7272

7373
def __init__(
7474
self,
75-
path: str = ".",
7675
cache_dir: Path = DEFAULT_CACHE_FOLDER,
77-
use_git: bool = True,
7876
integration_material_social_cards: Optional[
7977
IntegrationMaterialSocialCards
8078
] = None,
79+
mkdocs_command_is_on_serve: bool = False,
80+
path: str = ".",
81+
use_git: bool = True,
8182
):
8283
"""Class hosting the plugin logic.
8384
@@ -87,6 +88,13 @@ def __init__(
8788
integration_material_social_cards (bool, optional): option to enable
8889
integration with Social Cards plugin from Material theme. Defaults to True.
8990
"""
91+
self.mkdocs_command_is_on_serve = mkdocs_command_is_on_serve
92+
if self.mkdocs_command_is_on_serve:
93+
logger.debug(
94+
"Mkdocs serve - Fetching remote images length is disabled to avoid "
95+
"HTTP errors."
96+
)
97+
9098
if use_git:
9199
logger.debug("Git use is enabled.")
92100
try:
@@ -654,6 +662,9 @@ def get_remote_image_length(
654662
Returns:
655663
int | None: image length as int or None
656664
"""
665+
if self.mkdocs_command_is_on_serve:
666+
return None
667+
657668
# first, try HEAD request to avoid downloading the image
658669
try:
659670
attempt += 1

0 commit comments

Comments
 (0)