From 15c70e6836d818ed5bee0338d0410f9d94d8a504 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 17 Apr 2020 00:53:07 +0200 Subject: [PATCH] Split calendar view into months There is one overview page with one entry per month (currently the longest thread, could also be an abbreviated list of threads, but not all of the threads (or we are back where we started).The entries link to the monthly pages which contain links to all threads with at least one mail in that month. --- mbox2web | 57 ++++++++++++++++++++++++++++++++++------- templates/by_month.html | 33 ++++++++++++++++++++++++ templates/overview.html | 39 ++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 templates/by_month.html create mode 100644 templates/overview.html diff --git a/mbox2web b/mbox2web index f238dc8..cd18196 100755 --- a/mbox2web +++ b/mbox2web @@ -1,5 +1,6 @@ #!/usr/bin/python3 +from collections import defaultdict import datetime import email.header import email.parser @@ -1144,6 +1145,31 @@ class Thread: def subject(self): return list(self.messages.values())[0].subject + def index(self, message): + for i, m in enumerate(sorted(self.messages.values(), key=lambda x: x.date)): + if m == message: + return i + +class Month: + def __init__(self, year, month): + self.year = year + self.month = month + self.threads = defaultdict(int) + + def add(self, thread): + self.threads[thread] += 1 + + @property + def longest_thread(self): + thread = None + maxcount = 0 + for t, c in self.threads.items(): + if c > maxcount: + maxcount = c + thread = t + print("longest_thread: found thread", thread) + return thread + class Archive: def __init__(self): @@ -1215,16 +1241,19 @@ class Archive: def webify_calendar(self): - caltmpl = jenv.get_template("calendar.html") + + ovrtmpl = jenv.get_template("overview.html") + bmotmpl = jenv.get_template("by_month.html") cal = {} for t in self.thread_list: - y = t.date.year - m = t.date.month - if y not in cal: - cal[y] = {} - if m not in cal[y]: - cal[y][m] = [] - cal[y][m].append(t) + for m in t.messages.values(): + y = m.date.year + m = m.date.month + if y not in cal: + cal[y] = {} + if m not in cal[y]: + cal[y][m] = Month(y, m) + cal[y][m].add(t) caldir = basedir + "/cal" os.makedirs(caldir, exist_ok=True) with open(caldir + "/index.html", "w") as hfd: @@ -1232,8 +1261,18 @@ class Archive: "list": "LUGA", "cal": cal, } - calhtml = caltmpl.render(context) + calhtml = ovrtmpl.render(context) hfd.write(calhtml) + for y in cal.keys(): + for m in cal[y].keys(): + monthdir = f"{caldir}/{y}/{m}" + os.makedirs(monthdir, exist_ok=True) + with open(monthdir + "/index.html", "w") as hfd: + context = { + "month": cal[y][m] + } + monthhtml = bmotmpl.render(context) + hfd.write(monthhtml) def self_check(self): diff --git a/templates/by_month.html b/templates/by_month.html new file mode 100644 index 0000000..61bd229 --- /dev/null +++ b/templates/by_month.html @@ -0,0 +1,33 @@ + + + + + + {{list}}: {{month.year}}-{{month.month}} + + + + +

Mailinglist {{list}} {{month.year}}-{{month.month}}

+ +
+ +
+ + + + + diff --git a/templates/overview.html b/templates/overview.html new file mode 100644 index 0000000..86b56f1 --- /dev/null +++ b/templates/overview.html @@ -0,0 +1,39 @@ + + + + + + {{list}}: Overview + + + + +
+

Mailinglist {{list}} nach Datum

+
+ +
+ {% for y in cal | dictsort(reverse=True) %} +

{{y.0}}

+ + + + + + {% for m in y.1 | dictsort(reverse=True) %} + + + + + {% endfor %} +
MonatLängster Thread
{{m.0}}{{m.1.longest_thread.subject}}
+ {% endfor %} +
+ + + + +