add examples

This commit is contained in:
relikd
2022-03-31 04:20:01 +02:00
parent c9c1ab69b1
commit 2de02ed50c
22 changed files with 433 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from lektor.pluginsystem import Plugin
from lektor.utils import slugify
import re
class AdvancedGroupByPlugin(Plugin):
def on_groupby_before_build_all(self, groupby, builder, **extra):
# load config
regex = self.get_config().get('match')
try:
regex = re.compile(regex)
except Exception as e:
print('inlinetags.regex not valid: ' + str(e))
return
# since we load and use a config file, we need to track the dependency
@groupby.depends_on(self.config_filename)
@groupby.watch('/', 'testC', slug='advanced/{group}/',
template='example-advanced.html')
def convert_replace_example(args):
# args.field assumed to be Markdown
obj = args.field.source
for match in regex.finditer(obj):
tag = match.group(1)
yield slugify(tag), tag
def _fn(match: re.Match) -> str:
tag = match.group(1)
return f'<a href="/advanced/{slugify(tag)}/">{tag}</a>'
args.field.source = regex.sub(_fn, obj)