update example to v0.9.3

This commit is contained in:
relikd
2022-04-06 13:16:44 +02:00
parent a6d9f715f9
commit 637524a615
9 changed files with 78 additions and 52 deletions

View File

@@ -1,17 +1,26 @@
# -*- coding: utf-8 -*-
from lektor.pluginsystem import Plugin
from lektor.utils import slugify
from typing import Iterator, Tuple
from datetime import datetime
from lektor_groupby import GroupBy, GroupByCallbackArgs
class SimpleGroupByPlugin(Plugin):
def on_groupby_after_build_all(self, groupby, builder, **extra):
@groupby.watch('/blog', 'testB', slug='simple/{group}/index.html',
template='example-simple.html', flatten=True)
def convert_simple_example(args):
def on_groupby_before_build_all(self, groupby: GroupBy, builder, **extra):
watcher = groupby.add_watcher('testB', {
'root': '/blog',
'slug': 'simple/{key}/index.html',
'template': 'example-simple.html',
})
watcher.config.set_key_map({'Foo': 'bar'})
watcher.config.set_fields({'date': datetime.now()})
@watcher.grouping(flatten=True)
def fn_simple(args: GroupByCallbackArgs) -> Iterator[Tuple[str, dict]]:
# Yield groups
value = args.field # list type since model is 'strings' type
value = args.field # type: list # since model is 'strings' type
for tag in value:
yield slugify(tag), {'val': tag, 'tags_in_page': len(value)}
yield tag, {'tags_in_page': value}
# Everything below is just for documentation purposes
page = args.record # extract additional info from source
fieldKey, flowIndex, flowKey = args.key # or get field index
@@ -19,6 +28,6 @@ class SimpleGroupByPlugin(Plugin):
obj = page[fieldKey]
else:
obj = page[fieldKey].blocks[flowIndex].get(flowKey)
print('page:', page)
print(' obj:', obj)
print()
print('[simple] page:', page)
print('[simple] obj:', obj)
print('[simple] ')