-#!/usr/bin/env python2
+#!/usr/bin/env python3
"""Creates a webpage with all entries of a .bib file"""
-__version__ = "1.0"
+__version__ = "1.1"
__author__ = "Stefan Huber"
__email__ = "shuber@sthu.org"
# OTHER DEALINGS IN THE SOFTWARE.
-import os, sys, getopt
+import os, sys, getopt, re
def format_latex(text):
- return text.replace('{', '').replace('}', '').replace('\\', '')
+ # Get rid of matching dollar signs
+ text = re.sub(r'\$([^\$]*)\$', r'\1', text)
+
+ # Replace text
+ subst = {
+ '\\"a': 'ä',
+ '\\"o': 'ö',
+ '\\"u': 'u',
+ '\mathcal': '',
+ '{': '',
+ '}': '',
+ '\\': '',
+ '~': ' ',
+ '---': '–',
+ '--': '–',
+ }
+
+ for a, b in subst.items():
+ text = text.replace(a, b)
+
+ return text
def format_field_span(type, value):
return "<span class=bibentry_" + type + ">" + format_latex(value) + "</span>"
return ""
def format_author(a):
- return ' '.join(' '.join(p) for p in (a.first(), a.middle(), a.prelast(), a.last(), a.lineage()) if p)
+ return ' '.join(' '.join(p) for p in (a.first_names, a.middle_names, a.prelast_names, a.last_names, a.lineage_names) if p)
def format_authors(entry):
return ", ".join([format_author(a) for a in entry.persons['author']])
format_field(entry, 'number', pre='(', post=')'))
line.append(format_field(entry, 'month', post=' ') + \
format_field(entry, 'year'))
- line = filter(lambda l: l != "", line)
+ line.append(format_field(entry, 'note'))
+ line = filter(lambda l: l != "", line)
return [where, ", ".join(line)]
def format_details_inproceedings(entry):
line.append(format_field(entry, 'address'))
line.append(format_field(entry, 'month', post=' ') + \
format_field(entry, 'year'))
+ line.append(format_field(entry, 'isbn', pre='ISBN '))
+ line.append(format_field(entry, 'note'))
+
line = filter(lambda l: l != "", line)
return [where, ", ".join(line)]
line.append(format_field(entry, 'school'))
line.append(format_field(entry, 'month', post=' ') + \
format_field(entry, 'year'))
+ line.append(format_field(entry, 'note'))
+
line = filter(lambda l: l != "", line)
return [", ".join(line)]
line.append(format_field(entry, 'isbn', pre='ISBN '))
line.append(format_field(entry, 'month', post=' ') + \
format_field(entry, 'year'))
+ line.append(format_field(entry, 'note'))
+
line = filter(lambda l: l != "", line)
return [", ".join(line)]
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>')
+ url = format_field(entry, 'url', pre='<a href="', post='">[url]</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([doi, webpdf, weblink, webslides, weberrata])
+ return " ".join([doi, webpdf, weblink, url, webslides, weberrata])
def format_entry(entry):
lines = []
return "<br/>\n".join(lines)
-def entryCompareDate(p1, p2):
- k1, e1 = p1
- k2, e2 = p2
+def entryDateSortKey(p):
+ k, e = p
+ 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'}
- def toStr(e):
- 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'}
- month = e.fields['month'].lower()[0:3]
- if month in month2num:
- month = month2num[month]
- else:
- month = ""
- return e.fields['year'] + "-" + month
+ if not 'month' in e.fields:
+ return e.fields['year']
+
+ month = e.fields['month'].lower()[0:3]
+ if month in month2num:
+ month = month2num[month]
+ else:
+ month = ""
- return cmp(toStr(e1), toStr(e2))
+ return e.fields['year'] + "-" + month
def usage():
print("<h2>" + year + "</h2>")
- iteritems = list(entries.iteritems())
- iteritems.sort(cmp=entryCompareDate, reverse=True)
+ iteritems = list(entries.items())
+ iteritems.sort(key=entryDateSortKey, reverse=True)
for key, entry in iteritems:
if entry.fields['year'] != year:
print("<div class=bibentry>")
print("<a class=bibentry_key id=" + key + ">[" + key + "]</a><br/>")
- print(format_entry(entry).encode('utf8'))
+ e = format_entry(entry)
+ print(e)
print("</div>\n")