From d4d771618824ada5d34f22031e3748de27cd68b5 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Thu, 3 Aug 2023 21:15:29 +0200 Subject: [PATCH] bib2html.py: Make use of date field --- bib2html.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bib2html.py b/bib2html.py index 5d5b4db..a595f42 100755 --- a/bib2html.py +++ b/bib2html.py @@ -32,6 +32,7 @@ __license__ = "MIT" import os, sys, getopt, re +import dateutil.parser def format_latex(text): @@ -159,6 +160,9 @@ def format_entry(entry): def entryDateSortKey(p): k, e = p + if 'date' in e.fields: + return e.fields['date'] + month2num = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \ 'apr' : '04', 'may' : '05', 'jun' : '06', \ 'jul' : '07', 'aug' : '08', 'sep' : '09', \ @@ -176,6 +180,17 @@ def entryDateSortKey(p): return e.fields['year'] + "-" + month +def entryGetYear(e): + if 'year' in e.fields: + return e.fields['year'] + + if 'date' in e.fields: + dt = dateutil.parser.isoparse(e.fields['date']) + return str(dt.year) + + return None + + def usage(): """Print usage text of this program""" @@ -222,7 +237,7 @@ if __name__ == "__main__": bib_data = parser.parse_file(bibfile) entries = bib_data.entries - years = list(set([ b.fields['year'] for b in entries.values() ])) + years = list(set([entryGetYear(e) for e in entries.values()])) years.sort(reverse=True) for year in years: @@ -233,7 +248,7 @@ if __name__ == "__main__": iteritems.sort(key=entryDateSortKey, reverse=True) for key, entry in iteritems: - if entry.fields['year'] != year: + if entryGetYear(entry) != year: continue print("
") -- 2.39.5