5 Commits
v0.9.9 ... main

Author SHA1 Message Date
relikd
5bbe6d2360 chore: bump v1.0.0 2023-03-04 18:19:26 +01:00
relikd
1188216788 fix: remove duplicates from vobj.children 2022-12-22 00:18:25 +01:00
relikd
b603fb9dd2 feat: add unique=False to vgroups filter 2022-12-21 20:12:13 +01:00
relikd
05b9fbf20a refactor: vgroups set default attr recursive=True 2022-12-21 19:50:27 +01:00
relikd
7039fb3a63 fix: yield unique vgroups while keeping sort order 2022-12-21 19:22:59 +01:00
5 changed files with 34 additions and 9 deletions

View File

@@ -8,10 +8,24 @@ and this project does adhere to [Semantic Versioning](https://semver.org/spec/v2
## [Unreleased]
## [1.0.0] 2023-03-04
### Added
- `vgroups` filter now supports `unique=False` to return a list of all entries including duplicates (default: `True`)
### Fixed
- Preserves original sort order in `vgroups` filter if `unique=True`
- Remove duplicates from `GroupBySource` children
### Changed
- `vgroups` filter uses `recursive=True` by default
## [0.9.9] 2022-12-21
### Fixed
- Keep original sorting order in `vgroups` filter if no `order_by` is set.
- Keep original sorting order in `vgroups` filter if no `order_by` is set
@@ -149,7 +163,8 @@ and this project does adhere to [Semantic Versioning](https://semver.org/spec/v2
Initial release
[Unreleased]: https://github.com/relikd/lektor-groupby-plugin/compare/v0.9.9...HEAD
[Unreleased]: https://github.com/relikd/lektor-groupby-plugin/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/relikd/lektor-groupby-plugin/compare/v0.9.9...v1.0.0
[0.9.9]: https://github.com/relikd/lektor-groupby-plugin/compare/v0.9.8...v0.9.9
[0.9.8]: https://github.com/relikd/lektor-groupby-plugin/compare/v0.9.7...v0.9.8
[0.9.7]: https://github.com/relikd/lektor-groupby-plugin/compare/v0.9.6...v0.9.7

View File

@@ -3,7 +3,6 @@
A generic grouping / clustering plugin.
Can be used for tagging or similar tasks.
The grouping algorithm is performed once.
Contrary to, at least, cubic runtime if doing the same with Pad queries.
Install this plugin or modify your Lektor project file:

View File

@@ -1,5 +1,5 @@
from lektor.context import get_ctx
from typing import TYPE_CHECKING, Set, List, Union, Iterable, Iterator
from typing import TYPE_CHECKING, Set, List, Dict, Union, Iterable, Iterator
import weakref
from .util import split_strip
if TYPE_CHECKING:
@@ -49,8 +49,9 @@ class VGroups:
*,
fields: Union[str, Iterable[str], None] = None,
flows: Union[str, Iterable[str], None] = None,
recursive: bool = False,
order_by: Union[str, Iterable[str], None] = None,
recursive: bool = True,
unique: bool = True,
) -> Iterator['GroupBySource']:
''' Extract all referencing groupby virtual objects from a page. '''
# prepare filter
@@ -68,7 +69,12 @@ class VGroups:
GroupByRef.of(builder).make_once(keys) # ensure did cluster before use
# find groups
proc_list = [record]
done_list = [] # type: List[GroupBySource]
# Note: An ordered Set would be more approptiate but there is none.
# So lets use the insert order of dict (guaranteed since Python 3.7)
_only_uniques = {} # type: Dict[GroupBySource, None]
_w_duplicates = [] # type: List[GroupBySource]
while proc_list:
page = proc_list.pop(0)
if recursive and hasattr(page, 'children'):
@@ -80,7 +86,12 @@ class VGroups:
continue
if keys and vobj().config.key not in keys:
continue
done_list.append(vobj())
if unique:
_only_uniques[vobj()] = None # we only need the keys()
else:
_w_duplicates.append(vobj())
done_list = _only_uniques if unique else _w_duplicates
# manage config dependencies
deps = set() # type: Set[str]

View File

@@ -46,7 +46,7 @@ class GroupBySource(VirtualSourceObject):
self.page_num = page_num
def append_child(self, child: 'Record', key_obj: Any) -> None:
if child not in self.__children:
if child.path not in self.__children:
self.__children.append(child.path)
# __key_obj_map is later used to find most used key_obj
self.__key_obj_map.append(key_obj)

View File

@@ -13,7 +13,7 @@ setup(
},
author='relikd',
url='https://github.com/relikd/lektor-groupby-plugin',
version='0.9.9',
version='1.0.0',
description='Cluster arbitrary records with field attribute keyword.',
long_description=longdesc,
long_description_content_type="text/markdown",