config.root trailing slash + allow any in fields

This commit is contained in:
relikd
2022-04-06 12:29:35 +02:00
parent ebc29459ec
commit d6df547682
2 changed files with 5 additions and 6 deletions

View File

@@ -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.

View File

@@ -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:
'''