2022-01-20 07:02:55 +01:00
# lektor-citation
2022-01-21 22:22:49 +01:00
An APA-styled citation plugin for the lektor static content management system (https://getlektor.com).
## Preparations
Install the plugin by
```
lektor plugin add lektor-citation
```
or by copying this repository into the _ packages _ -folder of your lektor-project.
Create an _ citation.ini _ in its _ configs _ -folder:
```
[Bibtex]
file = Literature.bib
2022-01-27 22:00:58 +01:00
[default]
priority = url
link = /for-example/link-to-your/biblioprahy
2022-01-21 22:22:49 +01:00
```
And put a _ Literature.bib _ BibTex-file into the project's _ assets _ -folder respectively.
## Jinja_env
2022-01-25 00:24:48 +01:00
### Bibliography
2022-01-21 22:22:49 +01:00
To get a formated output of your whole BibTex library you can either
1. Use method citation\_short\_output in the template of your literature page. It creates an unordered list of entries.
```
<ul id="literatur">
{% for entry in citation_entries() %}
{{ citation_short_output(entry)|decode|safe }}
{% endfor %}
</ul>
```
2. Use method citation\_full\_output instead. This creates a more complete html-output for every entry.
```
{% for entry in citation_entries() %}
{{ citation_full_output(entry)|decode|safe }}
{% endfor %}
```
produces
```
<h2>{title}</h2><h3>{authors} ({pubYear})</h3>
<p>{note}</p>
<dl class="literature">
<dt class="edition"></dt>
<dd>{edition}</dd>
<dt class="editors"></dt>
<dd>{editors}</dd>
<dt class="pages"></dt>
<dd>{pages}</dd>
<dt class="issbn"></dt>
<dd>{issbn}</dd>
<dt class="publisher"></dt>
<dd>{publisher}</dd>
</dl>
```
2022-01-22 18:32:03 +01:00
3. You may also use the citation\_entry method in combination with [pybtex*s __Entry__-class ](https://docs.pybtex.org/api/parsing.html#pybtex.database.Entry ). For example:
```
<ul>
{% for entry in citation_entries() %}
<li>{{ citation_entry(entry).fields['title'] |decode }}</li>
{% endfor %}
</ul>
```
This creates an unordered list of all the titles of your bibtex file.
Of course you can also use citation\_entry without a loop and put any id of your bibtex entries into it as parameter.
2022-01-25 00:24:48 +01:00
Alternatively to the pybtex methods you can use the following **jinja_env globals ** :
2022-01-25 00:29:55 +01:00
citation_authors_short(entry)
citation_authors_full(entry)
citation_editors_short(entry)
citation_editors_full(entry)
citation_pubYear(entry)
citation_edition(entry)
citation_publisher(entry)
citation_title(entry)
citation_url(entry)
citation_issbn(entry)
citation_pages(entry)
citation_note(entry)
2022-01-25 00:24:48 +01:00
### In-text Cites
To cite a certain entry in your texts you can use the **jinja_env globals ** :
2022-01-25 00:29:55 +01:00
citation_full_cite(id, link="")
citation_full_citeNP(id, link="")
2022-01-25 00:24:48 +01:00
Both methods create a complete hyperlink inside your text for the entry with _ id _ . You may give it any url to the _ link _ parameter to e.g. link it to your bibliography page. The NP in the second stands for _ No Parantheses _ . So you'll receive e.g.
AuthorI & AuthorII (2019)
or
(AuthorI & AuthorII, 2019)
2022-01-27 22:00:58 +01:00
#### link parameter
Which url is used for your citation's link depends on what you set in the _ citation.ini _ file.
* If you set _ priority _ in the _ default _ section to __url __ the link is set to the value of the _ url _ field of the entry.
* If there's no value in it the default-link you may set with _ link _ in the same section is used.
* If you set the _ link _ parameter of the function it overwrites the former options.
2022-01-25 00:24:48 +01:00
Thanks to the **lektor-jinja-content ** plugin which is a dependency of this plugin you might also use the globals inside your markdown or html contents, too.