Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19bee043fc | ||
|
|
6d7456a85b | ||
|
|
a9ce2a2e9a |
1
Makefile
1
Makefile
@@ -1,4 +1,5 @@
|
||||
dist: setup.py lektor_inlinetags.py
|
||||
[ -z "$${VIRTUAL_ENV}" ] # you can not do this inside a virtual environment.
|
||||
@echo Building...
|
||||
python3 setup.py sdist bdist_wheel
|
||||
rm -rf ./*.egg-info/ ./build/ MANIFEST
|
||||
|
||||
@@ -31,15 +31,15 @@ In your plugin config (`configs/inlinetags.ini`):
|
||||
```ini
|
||||
[inlinetags]
|
||||
root = /
|
||||
slug = "tag/{}/index.html".format(this.key)
|
||||
slug = tag/{key}/
|
||||
template = tag-page.html
|
||||
|
||||
[inlinetags.pattern]
|
||||
match = {{([^}]{1,32})}}
|
||||
replace = <a class="tag" href="/tag/{key}/">{name}</a>
|
||||
replace = <a class="tag" href="{url}">{name}</a>
|
||||
|
||||
[inlinetags.fields]
|
||||
title = "Tagged: " ~ this.group
|
||||
title = "Tagged: " ~ this.key_obj
|
||||
|
||||
[inlinetags.key_map]
|
||||
C# = c-sharp
|
||||
|
||||
5
example/Example.lektorproject
Normal file
5
example/Example.lektorproject
Normal file
@@ -0,0 +1,5 @@
|
||||
[project]
|
||||
name = Inlinetags Example
|
||||
|
||||
[packages]
|
||||
lektor-inlinetags = 0.9.2
|
||||
7
example/Makefile
Normal file
7
example/Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
.PHONY: server clean plugins
|
||||
server:
|
||||
lektor server
|
||||
clean:
|
||||
lektor clean --yes -v
|
||||
plugins:
|
||||
lektor plugins flush-cache && lektor plugins list
|
||||
23
example/configs/inlinetags.ini
Normal file
23
example/configs/inlinetags.ini
Normal file
@@ -0,0 +1,23 @@
|
||||
[inlinetags]
|
||||
root = /
|
||||
slug = tag/{key}/
|
||||
template = tag-page.html
|
||||
|
||||
[inlinetags.pattern]
|
||||
match = {{([^}]{1,32})}}
|
||||
replace = <a class="tag" href="{url}">{name}</a>
|
||||
|
||||
[inlinetags.fields]
|
||||
title = "Tagged: " ~ this.key_obj
|
||||
|
||||
[inlinetags.key_map]
|
||||
C# = c-sharp
|
||||
|
||||
|
||||
[inlinetags_hidden]
|
||||
slug = hidden-tag/{key}/
|
||||
template = tag-page.html
|
||||
|
||||
[inlinetags_hidden.pattern]
|
||||
match = {{([^}]{1,32})}}
|
||||
replace = {name}
|
||||
3
example/content/contents.lr
Normal file
3
example/content/contents.lr
Normal file
@@ -0,0 +1,3 @@
|
||||
title: Use Inlinetags in {{title}}!
|
||||
---
|
||||
body: This is a {{demo}} {{demo}} website that shows how to use {{Lektor}} with inline {{tags}}. Test {{C#}}.
|
||||
13
example/models/page.ini
Normal file
13
example/models/page.ini
Normal file
@@ -0,0 +1,13 @@
|
||||
[model]
|
||||
name = Page
|
||||
label = {{ this.title }}
|
||||
|
||||
[fields.title]
|
||||
label = Title
|
||||
type = string
|
||||
inlinetags_hidden = true
|
||||
|
||||
[fields.body]
|
||||
label = Body
|
||||
type = markdown
|
||||
inlinetags = true
|
||||
21
example/templates/page.html
Normal file
21
example/templates/page.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Inlinetags</title>
|
||||
<style type="text/css">
|
||||
main { margin: 1em; }
|
||||
footer { padding: 1em; background: #DDD; }
|
||||
</style>
|
||||
<body>
|
||||
<main>
|
||||
{# Using "|safe" to allow clickable links in title #}
|
||||
<h2>{{ this.title|safe }}</h2>
|
||||
{% block body %}{{ this.body }}{% endblock %}
|
||||
</main>
|
||||
<footer>
|
||||
<a href="/">Root</a>,
|
||||
Tags:
|
||||
{%- for x in this|vgroups(recursive=True, order_by='key_obj') %}
|
||||
<a href="{{ x|url }}"><{{x.key_obj}}></a>
|
||||
{%- endfor %}
|
||||
</footer>
|
||||
</body>
|
||||
10
example/templates/tag-page.html
Normal file
10
example/templates/tag-page.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{% extends "page.html" %}
|
||||
{% block body %}
|
||||
<p>Key: <b>{{this.key}}</b> | Object: <b>{{this.key_obj}}</b></p>
|
||||
Page with <b>{{this.children.count()}}</b> tag(s):
|
||||
<ul>
|
||||
{%- for child in this.children|unique %}
|
||||
<li><a href="{{child|url}}">{{child.title}}</a></li>
|
||||
{%- endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
@@ -2,7 +2,6 @@ from lektor.context import get_ctx
|
||||
from lektor.markdown import Markup # isinstance
|
||||
from lektor.pluginsystem import Plugin # subclass
|
||||
import re
|
||||
from lektor_groupby.util import report_config_error
|
||||
from typing import TYPE_CHECKING, Set, Dict, Any, Generator
|
||||
if TYPE_CHECKING:
|
||||
from lektor.pluginsystem import IniFile
|
||||
@@ -39,10 +38,11 @@ class InlineTagsPlugin(Plugin):
|
||||
try:
|
||||
regex = re.compile(regex_str)
|
||||
except Exception as e:
|
||||
report_config_error(sect_key, 'pattern.match', regex_str, e)
|
||||
return False
|
||||
raise ValueError(
|
||||
'Invalid regex patter [{}.{}] = "{}" – Error: {}'.format(
|
||||
sect_key, 'pattern.match', regex_str, repr(e)))
|
||||
|
||||
watcher = groupby.add_watcher(sect_key, config)
|
||||
watcher = groupby.add_watcher(sect_key, config, pre_build=True)
|
||||
|
||||
@watcher.grouping()
|
||||
def _fn(args: 'GroupByCallbackArgs') -> Generator[str, str, None]:
|
||||
@@ -54,14 +54,15 @@ class InlineTagsPlugin(Plugin):
|
||||
if isinstance(obj, str) and str:
|
||||
for match in regex.finditer(obj):
|
||||
name = match.group(1)
|
||||
_tags[name] = yield name
|
||||
vobj = yield name
|
||||
_tags[name] = vobj.url_path
|
||||
# ignore other types (int, float, date, url, undefined)
|
||||
|
||||
# replace inline-tags with hyperlink
|
||||
if _tags:
|
||||
def _repl_tags(match: re.Match) -> str:
|
||||
name = match.group(1)
|
||||
return tag_replace.format(key=_tags[name], name=name)
|
||||
return tag_replace.format(url=_tags[name], name=name)
|
||||
|
||||
args.record._inlinetag_modified = True
|
||||
# get field value
|
||||
|
||||
4
setup.py
4
setup.py
@@ -6,7 +6,7 @@ with open('README.md') as fp:
|
||||
setup(
|
||||
name='lektor-inlinetags',
|
||||
py_modules=['lektor_inlinetags'],
|
||||
install_requires=['lektor-groupby>=0.9.6'],
|
||||
install_requires=['lektor-groupby==0.9.8'],
|
||||
entry_points={
|
||||
'lektor.plugins': [
|
||||
'inlinetags = lektor_inlinetags:InlineTagsPlugin',
|
||||
@@ -14,7 +14,7 @@ setup(
|
||||
},
|
||||
author='relikd',
|
||||
url='https://github.com/relikd/lektor-inlinetags-plugin',
|
||||
version='0.9.1',
|
||||
version='0.9.2',
|
||||
description='Auto-detect and reference tags inside written text.',
|
||||
long_description=longdesc,
|
||||
long_description_content_type="text/markdown",
|
||||
|
||||
Reference in New Issue
Block a user