From 38c477f5c9ea88e39051a688cab8302cb5abfce3 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Sun, 23 Jun 2024 20:05:43 +0200 Subject: [PATCH] fix(config): do not raise error for bad date_from_meta.default_time value and fallback to default Closes #290 --- mkdocs_rss_plugin/config.py | 3 +-- mkdocs_rss_plugin/plugin.py | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mkdocs_rss_plugin/config.py b/mkdocs_rss_plugin/config.py index 195591e..8212df4 100644 --- a/mkdocs_rss_plugin/config.py +++ b/mkdocs_rss_plugin/config.py @@ -5,7 +5,6 @@ # ################################## # standard -from datetime import datetime from typing import Union # 3rd party @@ -25,7 +24,7 @@ class _DateFromMeta(Config): as_creation = config_options.Type(Union[bool, str], default="git") as_update = config_options.Type(Union[bool, str], default="git") datetime_format = config_options.Type(str, default="%Y-%m-%d %H:%M") - default_time = config_options.Type(str, default=datetime.min.strftime("%H:%M")) + default_time = config_options.Type(str, default="00:00") default_timezone = config_options.Type(str, default="UTC") diff --git a/mkdocs_rss_plugin/plugin.py b/mkdocs_rss_plugin/plugin.py index 1d783a7..61d3540 100644 --- a/mkdocs_rss_plugin/plugin.py +++ b/mkdocs_rss_plugin/plugin.py @@ -16,7 +16,6 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape from mkdocs.config import config_options from mkdocs.config.defaults import MkDocsConfig -from mkdocs.exceptions import PluginError from mkdocs.plugins import BasePlugin, event_priority, get_plugin_logger from mkdocs.structure.files import Files from mkdocs.structure.pages import Page @@ -169,12 +168,13 @@ def on_config(self, config: MkDocsConfig) -> MkDocsConfig: self.config.date_from_meta.default_time = datetime.strptime( self.config.date_from_meta.default_time, "%H:%M" ) - except ValueError as err: - raise PluginError( + except (TypeError, ValueError) as err: + logger.warning( "Config error: `date_from_meta.default_time` value " f"'{self.config.date_from_meta.default_time}' format doesn't match the " - f"expected format %H:%M. Trace: {err}" + f"expected format %H:%M. Fallback to the default value. Trace: {err}" ) + self.config.date_from_meta.default_time = "00:00" if self.config.use_git: logger.debug(