From d6df54768244643d050fa4e3ea86ca58d9bcceb8 Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 6 Apr 2022 12:29:35 +0200 Subject: [PATCH] config.root trailing slash + allow any in fields --- lektor_groupby/config.py | 8 ++++---- lektor_groupby/watcher.py | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lektor_groupby/config.py b/lektor_groupby/config.py index ec46081..828c8a7 100644 --- a/lektor_groupby/config.py +++ b/lektor_groupby/config.py @@ -1,7 +1,7 @@ from inifile import IniFile from lektor.utils import slugify -from typing import Set, Dict, Optional, Union +from typing import Set, Dict, Optional, Union, Any AnyConfig = Union['Config', IniFile, Dict] @@ -23,20 +23,20 @@ class Config: template: Optional[str] = None, # default: "groupby-{attr}.html" ) -> None: self.key = key - self.root = (root or '/').rstrip('/') + '/' + self.root = (root or '/').rstrip('/') or '/' self.slug = slug or (key + '/{key}/') # key = GroupBySource.key self.template = template or f'groupby-{self.key}.html' # editable after init self.enabled = True self.dependencies = set() # type: Set[str] - self.fields = {} # type: Dict[str, str] + self.fields = {} # type: Dict[str, Any] self.key_map = {} # type: Dict[str, str] def slugify(self, k: str) -> str: ''' key_map replace and slugify. ''' return slugify(self.key_map.get(k, k)) # type: ignore[no-any-return] - def set_fields(self, fields: Optional[Dict[str, str]]) -> None: + def set_fields(self, fields: Optional[Dict[str, Any]]) -> None: ''' The fields dict is a mapping of attrib = Expression values. Each dict key will be added to the GroupBySource virtual object. diff --git a/lektor_groupby/watcher.py b/lektor_groupby/watcher.py index 30ffeb1..56d4a6f 100644 --- a/lektor_groupby/watcher.py +++ b/lektor_groupby/watcher.py @@ -158,8 +158,7 @@ class Watcher: def should_process(self, node: Record) -> bool: ''' Check if record path is being watched. ''' - p = node['_path'] # type: str - return p.startswith(self._root) or p + '/' == self._root + return node['_path'].startswith(self._root) def process(self, record: Record) -> None: '''