Skip to content

Commit 905dee5

Browse files
committed
feature(options): add cache_dir option
1 parent 96c0404 commit 905dee5

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

mkdocs_rss_plugin/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from mkdocs.config import config_options
99
from mkdocs.config.base import Config
1010

11+
# package
12+
from mkdocs_rss_plugin.constants import DEFAULT_CACHE_FOLDER
13+
1114
# ############################################################################
1215
# ########## Classes ###############
1316
# ##################################
@@ -42,6 +45,7 @@ class RssPluginConfig(Config):
4245
categories = config_options.Optional(
4346
config_options.ListOfItems(config_options.Type(str))
4447
)
48+
cache_dir = config_options.Type(str, default=f"{DEFAULT_CACHE_FOLDER.resolve()}")
4549
comments_path = config_options.Optional(config_options.Type(str))
4650
date_from_meta = config_options.SubConfig(_DateFromMeta)
4751
enabled = config_options.Type(bool, default=True)

mkdocs_rss_plugin/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# ########## Globals #############
1515
# ################################
1616

17+
DEFAULT_CACHE_FOLDER = Path(".cache/plugins/rss")
1718
DEFAULT_TEMPLATE_FOLDER = Path(__file__).parent / "templates"
1819
DEFAULT_TEMPLATE_FILENAME = DEFAULT_TEMPLATE_FOLDER / "rss.xml.jinja2"
1920
MKDOCS_LOGGER_NAME = "[RSS-plugin]"

mkdocs_rss_plugin/plugin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
9292
self.config.enabled = False
9393
return config
9494

95+
# cache dir
96+
self.cache_dir = Path(self.config.cache_dir)
97+
self.cache_dir.mkdir(parents=True, exist_ok=True)
98+
logger.debug(f"Caching HTTP requests to: {self.cache_dir.resolve()}")
99+
95100
# integrations - check if theme is Material and if social cards are enabled
96101
self.integration_material_social_cards = IntegrationMaterialSocialCards(
97102
mkdocs_config=config,
@@ -100,6 +105,7 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
100105

101106
# instantiate plugin tooling
102107
self.util = Util(
108+
cache_dir=self.cache_dir,
103109
use_git=self.config.use_git,
104110
integration_material_social_cards=self.integration_material_social_cards,
105111
)
@@ -169,10 +175,6 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
169175
self.config.date_from_meta.default_time = datetime.strptime(
170176
self.config.date_from_meta.default_time, "%H:%M"
171177
)
172-
print(
173-
self.config.date_from_meta.default_time,
174-
type(self.config.date_from_meta.default_time),
175-
)
176178
except (TypeError, ValueError) as err:
177179
logger.warning(
178180
"Config error: `date_from_meta.default_time` value "

0 commit comments

Comments
 (0)