From ebcc6924088e93cf34e2dda394348e50b1ffb568 Mon Sep 17 00:00:00 2001 From: Homer S Date: Thu, 20 Jan 2022 07:02:55 +0100 Subject: [PATCH] Initial commit. --- README.md | 4 ++++ lektor_citation.py | 36 ++++++++++++++++++++++++++++++++++++ setup.cfg | 2 ++ setup.py | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 README.md create mode 100644 lektor_citation.py create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..7759dd0 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# lektor-citation + +This is where a description of your plugin goes. +Provide usage instructions here. diff --git a/lektor_citation.py b/lektor_citation.py new file mode 100644 index 0000000..9f37453 --- /dev/null +++ b/lektor_citation.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +import os +from pylatexenc.latex2text import LatexNodes2Text +from pybtex.database import parse_file +from lektor.pluginsystem import Plugin + + +class CitationPlugin(Plugin): + name = 'lektor-citation' + description = u'This Plugin should extend lektor with APA-style citations using bibtex files. It is based on the known lektor-bibtex-support plugin by arunpersaud.' + + + def __init__(self, env, id): + super().__init__(env, id) + + config = self.get_config() + self.bibfile = config.get('Bibtex.file', []).strip() + + self.bib_data = parse_file(os.path.join(env.root_path, 'assets', self.bibfile)) + + + + def citation_entries(self): + return self.bib_data.entries + + def citation_entry(self, id): + return self.bib_data.entries[id] + + + + def on_setup_env(self, **extra): + + self.env.jinja_env.globals['citation_entries'] = self.citation_entries + self.env.jinja_env.globals['citation_entry'] = self.citation_entry + + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..3c6e79c --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal=1 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..70494c9 --- /dev/null +++ b/setup.py @@ -0,0 +1,39 @@ +import ast +import io +import re + +from setuptools import setup, find_packages + +with io.open('README.md', 'rt', encoding="utf8") as f: + readme = f.read() + +_description_re = re.compile(r'description\s+=\s+(?P.*)') + +with open('lektor_citation.py', 'rb') as f: + description = str(ast.literal_eval(_description_re.search( + f.read().decode('utf-8')).group(1))) + +setup( + author='Homer S', + author_email='homer77@ismus.net', + description=description, + keywords='Lektor plugin', + license='MIT', + long_description=readme, + long_description_content_type='text/markdown', + name='lektor-citation', + packages=find_packages(), + py_modules=['lektor_citation'], + # url='[link to your repository]', + version='0.1', + classifiers=[ + 'Framework :: Lektor', + 'Environment :: Plugins', + ], + entry_points={ + 'lektor.plugins': [ + 'citation = lektor_citation:CitationPlugin', + ] + }, + install_requires=['pybtex','pylatexenc'] +)