shithub: mkarchive

Download patch

ref: 73dcb5fa40e20c280552255b35edcabf9bd2bff8
parent: 5301ade2e6857e2c2c16be38b73f98d18f82e91f
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 28 14:27:27 EDT 2015

Generate date sorted archives.

--- a/mkarchive.py
+++ b/mkarchive.py
@@ -15,7 +15,7 @@
 opts = p.parse_args()
 
 def mailmonth(mail):
-    return time.strftime("%b-%Y", time.gmtime(os.path.getmtime(mail)))
+    return time.strftime("%Y-%b", time.gmtime(os.path.getmtime(mail)))
 
 def runmailadd(lst, mail):
     outdir = os.path.join(opts.outdir, lst, mailmonth(mail))
@@ -54,6 +54,9 @@
     with open(lastadded, 'w') as f:
         f.write(str(maxindex))
 
+def datesorted(dates):
+    return sorted(dates, reverse=True)
+
 def genindex(lst):
     listdir = os.path.join(opts.outdir, lst)
     with open(os.path.join(listdir, 'index.html'), 'w') as f:
@@ -73,7 +76,7 @@
                   </ul>
                 </nav>
               <article><ul>""" % (lst, lst))
-        for d in os.listdir(listdir):
+        for d in datesorted(os.listdir(listdir)):
             if os.path.isdir(os.path.join(listdir, d)):
                 f.write('<li><a href=%s>%s</a></li>' % (d, d))
         f.write("""