From af095b8d323e08b95101560b6a87897ea1a195c7 Mon Sep 17 00:00:00 2001 From: Homer S Date: Thu, 27 Jan 2022 21:48:23 +0100 Subject: [PATCH] Added links to cite methods. (Issue #1) --- lektor_citation.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lektor_citation.py b/lektor_citation.py index 042fc05..c3837e9 100644 --- a/lektor_citation.py +++ b/lektor_citation.py @@ -15,6 +15,8 @@ class CitationPlugin(Plugin): config = self.get_config() self.bibfile = config.get('Bibtex.file', []).strip() + self.default_prio = config.get('default.priority', []).strip() + self.default_link = config.get('default.link', []).strip() self.bib_data = parse_file(os.path.join(env.root_path, 'assets', self.bibfile)) @@ -223,18 +225,29 @@ class CitationPlugin(Plugin): """.format(eid = id, link = link, authors = authors, pubYear = year, title = title, edition = edition, publisher = publisher, editors = editors, pages = pages, issbn = issbn, note = note) return output - def citation_full_cite(self,id,link=""): + def citation_base_cite(self,id,link="",output=""): e = self.citation_entry(id) + + if len(link) > 1: + link = link + elif self.default_prio == "url": + link = self.get_url(e) + if len(link) < 2: + link = self.default_link + else: + link = self.default_link + authors = self.get_authors_short(e) year = self.get_pubYear(e) - output = """({authors}, {pubYear})""".format(link = link, id = id, authors = authors, pubYear = year) + output = output.format(link = link, id = id, authors = authors, pubYear = year) + return output + + def citation_full_cite(self,id,link=""): + output = self.citation_base_cite(id,link="",output="""({authors}, {pubYear})""") return output def citation_full_citeNP(self,id,link=""): - e = self.citation_entry(id) - authors = self.get_authors_short(e) - year = self.get_pubYear(e) - output = """{authors} ({pubYear})""".format(link = link, id = id, authors = authors, pubYear = year) + output = self.citation_base_cite(id,link="",output="""{authors} ({pubYear})""") return output def on_setup_env(self, **extra):