known issue fixed, update readme
This commit is contained in:
12
README.md
12
README.md
@@ -7,14 +7,8 @@ Of course, you can configure a different matching pattern, e.g., instead of the
|
||||
|
||||
This plugin is based on the [lektor-groupby](https://github.com/relikd/lektor-groupby-plugin) plugin.
|
||||
All configuration options from groupby can be used (including multiple attribute names).
|
||||
|
||||
|
||||
### Known issues
|
||||
|
||||
In rare cases, clicking on "Save Changes" will not replace the tags of the current page.
|
||||
It happens because the page is built concurrently (race condition).
|
||||
This affects only the currently edited page and only the inline replacements (the tags page is updated just fine).
|
||||
If this occurs to you, simply edit and save the page again.
|
||||
Further, you can access the tags of a page with the filter `|vgroups(key1, key2, recursive=False)` where key is `0..N` attribute keys.
|
||||
If no key is provided, all attributes will be returned – otherwise only matching attribute keys.
|
||||
|
||||
|
||||
### Example config file
|
||||
@@ -42,7 +36,7 @@ template = tag-page.html
|
||||
|
||||
[inlinetags.pattern]
|
||||
match = {{([^}]{1,32})}}
|
||||
replace = <a href="/tag/{key}/">{name}</a>
|
||||
replace = <a class="tag" href="/tag/{key}/">{name}</a>
|
||||
|
||||
[inlinetags.fields]
|
||||
title = "Tagged: " ~ this.group
|
||||
|
||||
@@ -1,34 +1,27 @@
|
||||
from lektor.context import get_ctx
|
||||
from lektor.db import Record # typing
|
||||
from lektor.markdown import Markup
|
||||
from lektor.pluginsystem import Plugin, IniFile # subclass
|
||||
from lektor.sourceobj import VirtualSourceObject as VObj # typing
|
||||
|
||||
from typing import Set, Dict, Any, Iterator, Generator
|
||||
from lektor.markdown import Markup # isinstance
|
||||
from lektor.pluginsystem import Plugin # subclass
|
||||
import re
|
||||
from lektor_groupby.groupby import GroupBy # typing
|
||||
from lektor_groupby.util import report_config_error
|
||||
from lektor_groupby.watcher import GroupByCallbackArgs # typing
|
||||
from typing import TYPE_CHECKING, Set, Dict, Any, Generator
|
||||
if TYPE_CHECKING:
|
||||
from lektor.pluginsystem import IniFile
|
||||
from lektor_groupby import GroupBy, GroupByCallbackArgs
|
||||
|
||||
|
||||
class InlineTagsPlugin(Plugin):
|
||||
name = 'inlinetags'
|
||||
description = 'Auto-detect and reference tags inside written text.'
|
||||
|
||||
def on_setup_env(self, **extra: Any) -> None:
|
||||
def _fn(record: Record, *, recursive: bool = False) -> Iterator[VObj]:
|
||||
fn = self.env.jinja_env.filters['vgroups']
|
||||
yield from fn(record, *self.config_keys, recursive=recursive)
|
||||
|
||||
self.env.jinja_env.filters.update(inlinetags=_fn)
|
||||
|
||||
def on_process_template_context(self, context: Dict, **extra: Any) -> None:
|
||||
if hasattr(context.get('this'), '_inlinetag_modified'):
|
||||
ctx = get_ctx()
|
||||
if ctx:
|
||||
ctx.record_dependency(self.config_filename)
|
||||
|
||||
def on_groupby_before_build_all(self, groupby: GroupBy, **ex: Any) -> None:
|
||||
def on_groupby_before_build_all(self, groupby: 'GroupBy', **extra: Any) \
|
||||
-> None:
|
||||
''' lektor-groupby entry point. '''
|
||||
self.config_keys = set() # type: Set[str]
|
||||
config = self.get_config()
|
||||
for sect in config.sections():
|
||||
@@ -37,7 +30,9 @@ class InlineTagsPlugin(Plugin):
|
||||
if self._add(sect, config, groupby):
|
||||
self.config_keys.add(sect)
|
||||
|
||||
def _add(self, sect_key: str, config: IniFile, groupby: GroupBy) -> bool:
|
||||
def _add(self, sect_key: str, config: 'IniFile', groupby: 'GroupBy') \
|
||||
-> bool:
|
||||
''' Parse config section and add callback. Return True on success. '''
|
||||
_pattern = config.section_as_dict(sect_key + '.pattern')
|
||||
regex_str = _pattern.get('match', r'{{([^}]{1,32})}}') # type: str
|
||||
tag_replace = _pattern.get('replace', '{name}') # type: str
|
||||
@@ -50,7 +45,7 @@ class InlineTagsPlugin(Plugin):
|
||||
watcher = groupby.add_watcher(sect_key, config)
|
||||
|
||||
@watcher.grouping()
|
||||
def _inlinetag(args: GroupByCallbackArgs) -> Generator[str, str, None]:
|
||||
def _fn(args: 'GroupByCallbackArgs') -> Generator[str, str, None]:
|
||||
arr = args.field if isinstance(args.field, list) else [args.field]
|
||||
_tags = {} # type: Dict[str, str]
|
||||
for obj in arr:
|
||||
|
||||
Reference in New Issue
Block a user