Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bbe6d2360 | ||
|
|
1188216788 | ||
|
|
b603fb9dd2 | ||
|
|
05b9fbf20a | ||
|
|
7039fb3a63 |
19
CHANGELOG.md
19
CHANGELOG.md
@@ -8,10 +8,24 @@ and this project does adhere to [Semantic Versioning](https://semver.org/spec/v2
|
|||||||
## [Unreleased]
|
## [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
|
## [0.9.9] – 2022-12-21
|
||||||
|
|
||||||
### Fixed
|
### 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
|
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.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.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
|
[0.9.7]: https://github.com/relikd/lektor-groupby-plugin/compare/v0.9.6...v0.9.7
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
A generic grouping / clustering plugin.
|
A generic grouping / clustering plugin.
|
||||||
Can be used for tagging or similar tasks.
|
Can be used for tagging or similar tasks.
|
||||||
The grouping algorithm is performed once.
|
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:
|
Install this plugin or modify your Lektor project file:
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from lektor.context import get_ctx
|
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
|
import weakref
|
||||||
from .util import split_strip
|
from .util import split_strip
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -49,8 +49,9 @@ class VGroups:
|
|||||||
*,
|
*,
|
||||||
fields: Union[str, Iterable[str], None] = None,
|
fields: Union[str, Iterable[str], None] = None,
|
||||||
flows: Union[str, Iterable[str], None] = None,
|
flows: Union[str, Iterable[str], None] = None,
|
||||||
recursive: bool = False,
|
|
||||||
order_by: Union[str, Iterable[str], None] = None,
|
order_by: Union[str, Iterable[str], None] = None,
|
||||||
|
recursive: bool = True,
|
||||||
|
unique: bool = True,
|
||||||
) -> Iterator['GroupBySource']:
|
) -> Iterator['GroupBySource']:
|
||||||
''' Extract all referencing groupby virtual objects from a page. '''
|
''' Extract all referencing groupby virtual objects from a page. '''
|
||||||
# prepare filter
|
# prepare filter
|
||||||
@@ -68,7 +69,12 @@ class VGroups:
|
|||||||
GroupByRef.of(builder).make_once(keys) # ensure did cluster before use
|
GroupByRef.of(builder).make_once(keys) # ensure did cluster before use
|
||||||
# find groups
|
# find groups
|
||||||
proc_list = [record]
|
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:
|
while proc_list:
|
||||||
page = proc_list.pop(0)
|
page = proc_list.pop(0)
|
||||||
if recursive and hasattr(page, 'children'):
|
if recursive and hasattr(page, 'children'):
|
||||||
@@ -80,7 +86,12 @@ class VGroups:
|
|||||||
continue
|
continue
|
||||||
if keys and vobj().config.key not in keys:
|
if keys and vobj().config.key not in keys:
|
||||||
continue
|
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
|
# manage config dependencies
|
||||||
deps = set() # type: Set[str]
|
deps = set() # type: Set[str]
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class GroupBySource(VirtualSourceObject):
|
|||||||
self.page_num = page_num
|
self.page_num = page_num
|
||||||
|
|
||||||
def append_child(self, child: 'Record', key_obj: Any) -> None:
|
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)
|
self.__children.append(child.path)
|
||||||
# __key_obj_map is later used to find most used key_obj
|
# __key_obj_map is later used to find most used key_obj
|
||||||
self.__key_obj_map.append(key_obj)
|
self.__key_obj_map.append(key_obj)
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -13,7 +13,7 @@ setup(
|
|||||||
},
|
},
|
||||||
author='relikd',
|
author='relikd',
|
||||||
url='https://github.com/relikd/lektor-groupby-plugin',
|
url='https://github.com/relikd/lektor-groupby-plugin',
|
||||||
version='0.9.9',
|
version='1.0.0',
|
||||||
description='Cluster arbitrary records with field attribute keyword.',
|
description='Cluster arbitrary records with field attribute keyword.',
|
||||||
long_description=longdesc,
|
long_description=longdesc,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|||||||
Reference in New Issue
Block a user