bib2html: adding DOI, pimping formatting
authorStefan Huber <shuber@sthu.org>
Thu, 7 Aug 2014 08:19:35 +0000 (10:19 +0200)
committerStefan Huber <shuber@sthu.org>
Thu, 7 Aug 2014 08:19:35 +0000 (10:19 +0200)
bib2html.py

index 28abd58ecbfebd88bfcdc56099a1a33619139f13..111d1085db02106616cfcf92011846fab8c2f0f6 100755 (executable)
@@ -42,7 +42,8 @@ def format_field_span(type, value):
 
 def format_field(bibentry, field, pre='', post=''):
     if field in bibentry.fields:
-        return format_field_span(field, pre + bibentry.fields[field] + post)
+        if bibentry.fields[field] != "":
+            return format_field_span(field, pre + bibentry.fields[field] + post)
     return ""
 
 def format_author(a):
@@ -95,12 +96,13 @@ def format_details_book(entry):
     return [", ".join(line)]
 
 def format_links(entry):
+    doi = format_field(entry, 'doi', pre='<a href="http://dx.doi.org/', post='">[DOI]</a>')
     webpdf = format_field(entry, 'webpdf', pre='<a href="', post='">[PDF]</a>')
     weblink = format_field(entry, 'weblink', pre='<a href="', post='">[link]</a>')
     webslides = format_field(entry, 'webslides', pre='<a href="', post='">[slides]</a>')
     weberrata = format_field(entry, 'weberrata', pre='<a href="',
             post='">[errata]</a>')
-    return " ".join([webpdf, weblink, webslides, weberrata])
+    return " ".join([doi, webpdf, weblink, webslides, weberrata])
 
 def format_entry(entry):
     lines = []
@@ -131,11 +133,16 @@ def entryCompareDate(p1, p2):
 
 
     def toStr(e):
-        month = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \
+        month2num = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \
                 'apr' : '04', 'may' : '05', 'jun' : '06', \
                 'jul' : '07', 'aug' : '08', 'sep' : '09', \
                 'oct' : '10', 'nov' : '11', 'dec' : '12'}
-        return e.fields['year'] + "-" + month[e.fields['month'].lower()[0:3]]
+        month = e.fields['month'].lower()[0:3]
+        if month in month2num:
+            month = month2num[month]
+        else:
+            month = ""
+        return e.fields['year'] + "-" + month
 
     return cmp(toStr(e1), toStr(e2))