Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouping by type of publications #8

Open
perror opened this issue Jul 19, 2014 · 0 comments
Open

Grouping by type of publications #8

perror opened this issue Jul 19, 2014 · 0 comments

Comments

@perror
Copy link

perror commented Jul 19, 2014

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant