From 45816ce2ef8e7fe566ecdf907fda56a0fb6ffd08 Mon Sep 17 00:00:00 2001 From: Homer S Date: Thu, 20 Jan 2022 23:53:50 +0100 Subject: [PATCH] A short citation output as an unordered list item added. --- lektor_citation.py | 50 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/lektor_citation.py b/lektor_citation.py index 9f37453..2697a58 100644 --- a/lektor_citation.py +++ b/lektor_citation.py @@ -18,19 +18,65 @@ class CitationPlugin(Plugin): 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 citation_short_output(self, id, link="?"): + e = self.citation_entry(id) + link = link+"#"+id + authors = "" + lAuthor = e.persons['author'] + n = 1 + for author in lAuthor: + if len(author.prelast_names) > 0: + authors += str(author.prelast_names) + authors += str(author.last_names[0]) + + if len(lAuthor) > 1: + + if n == (len(lAuthor) - 1): + authors += " \& " + elif n < (len(lAuthor) -1): + authors += ", " + n = n + 1 + + + year = e.fields['year'] + edition = "" + if 'edition' in e.fields.keys(): + edition = " ({ed}. Aufl.)".format(ed = edition) + else: + edition = "" + + + if 'publisher' in e.fields.keys(): + publisher = e.fields['publisher'] + if 'address' in e.fields.keys(): + location = e.fields['address'] + publisher = " {location}:{publisher}.".format(location = location, publisher = publisher) + elif publisher: + publisher = " {publisher}.".format(publisher = publisher) + else: + publisher = "" + + output = '
  • {authors} ({pubYear}). {title}{edition}. {publisher}'.format(eid = id, link = link, authors = authors, pubYear = year, title = e.fields['title'], edition = edition, publisher = publisher) + return output + + + def on_setup_env(self, **extra): + def decode_filter(value): + return LatexNodes2Text().latex_to_text(value) self.env.jinja_env.globals['citation_entries'] = self.citation_entries self.env.jinja_env.globals['citation_entry'] = self.citation_entry + self.env.jinja_env.globals['citation_short_output'] = self.citation_short_output + self.env.jinja_env.filters['decode'] = decode_filter +