pelican-bibtex
pelican-bibtex copied to clipboard
Grouping by type of publications
Nice work for this plugin ! I helped me a lot !
I took your plugin for my website, but I wanted to group the publication by types (Journal, Conference, ... and so on). So, I did a very little modification to your plugin to get this feature (sorry for my Python, I do not program often in this language, this code must certainly be improved that's why I didn't do a pull request):
diff --git a/pelican_bibtex.py b/pelican_bibtex.py
index be12dda..42e7f00 100644
--- a/pelican_bibtex.py
+++ b/pelican_bibtex.py
@@ -19,6 +19,28 @@ from pelican import signals
__version__ = '0.2'
+def entrytype(label):
+ entries = {
+ 'book' : (0, 'Book'),
+ 'incollection' : (1, 'Book in a Collection'),
+ 'booklet' : (2, 'Booklet'),
+ 'proceedings' : (3, 'Proceedings'),
+ 'inbook' : (4, 'Chapter in a Book'),
+ 'article' : (5, 'Journal'),
+ 'inproceedings' : (6, 'Conference'),
+ 'phdthesis' : (7, 'PhD Thesis'),
+ 'masterthesis' : (8, 'Master Thesis'),
+ 'techreport' : (9, 'Technical Report'),
+ 'manual' : (10, 'Manual'),
+ 'misc' : (11, 'Miscellaneous'),
+ 'unpublished' : (12, 'Unpublished'),
+ }
+
+ if label in entries:
+ return entries[label]
+ else:
+ return label
+
def add_publications(generator):
"""
Populates context with a list of BibTeX publications.
@@ -69,6 +91,7 @@ def add_publications(generator):
for formatted_entry in formatted_entries:
key = formatted_entry.key
entry = bibdata_all.entries[key]
+ type = entry.type
year = entry.fields.get('year')
pdf = entry.fields.pop('pdf', None)
slides = entry.fields.pop('slides', None)
@@ -80,13 +103,14 @@ def add_publications(generator):
Writer().write_stream(bibdata_this, bib_buf)
text = formatted_entry.text.render(html_backend)
- publications.append((key,
- year,
- text,
- bib_buf.getvalue(),
- pdf,
- slides,
- poster))
+ publications.append({'entry' : entrytype(type),
+ 'key' : key,
+ 'year' : year,
+ 'text' : text,
+ 'bibtex' : bib_buf.getvalue(),
+ 'pdf' : pdf,
+ 'slides' : slides,
+ 'poster' : poster})
generator.context['publications'] = publications
With this version, the HTML template can be as follow:
{% for group in publications|groupby('entry') %}
<h2>{{ group.grouper[1] }}</h2>
<ul>
{% for publication in group.list|sort(attribute='year')|reverse %}
<li id="{{ publication.key }}">{{ publication.text }}
[<a href="javascript:disp('{{ publication.bibtex|replace('\n', '<br>')|escape }}');">Bibtex</a>]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[<a href=\"publications/%s\">%s</a>]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul>
{% endfor %}
I don't know if you can find something useful in what I did, but if this is the case feel free to use and/or modify my code !