reconstruction of code from what i've been able to dig up master
authorBenjamin Mako Hill <mako@atdot.cc>
Tue, 16 Jun 2015 01:42:58 +0000 (18:42 -0700)
committerBenjamin Mako Hill <mako@atdot.cc>
Tue, 16 Jun 2015 01:42:58 +0000 (18:42 -0700)
README [new file with mode: 0644]
expandingarchives.py [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e186a64
--- /dev/null
+++ b/README
@@ -0,0 +1,19 @@
+1.
+
+To use this, you should install the expandingarchives.py file in your plugin directory.
+
+2.
+
+You will also need to download the Prototype Javascript library (just the
+prototype.js file) and make sure it is loaded with each page:
+
+http://prototypejs.org/
+
+3. 
+
+Finally, I added the following configuration options to my config.py:
+
+  py['archive_template_year'] = '<li><a href="#" onclick="Element.toggle(\'archive_year_contents_%(Y)s\'); return false;">%(Y)s</a><ul id="archive_year_contents_%(Y)s">%(month_contents)s</ul></li>'
+  py['archive_template_month'] = '<li><a href="%(base_url)s/%(Y)s/%(b)s">%(b)s/%(Y)s</a></li>'
+
+
diff --git a/expandingarchives.py b/expandingarchives.py
new file mode 100644 (file)
index 0000000..552edf1
--- /dev/null
@@ -0,0 +1,125 @@
+# vim: tabstop=4 shiftwidth=4
+"""
+Walks through your blog root figuring out all the available monthly archives in
+your blogs.  It generates html with this information and stores it in the
+$archivelinks variable which you can use in your head or foot templates.
+
+The vars available with typical example values are:
+    b      'Jun'
+    m      '6'
+    Y      '1978'
+    y      '78'
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify,
+merge, publish, distribute, sublicense, and/or sell copies of the
+Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+Copyright 2004, 2005 Wari Wahab
+Copyright 2006 Benjamin Mako Hill
+"""
+__author__ = "Benjamin Mako Hill <mako@atdot.cc>"
+__version__ = "$Id: pyarchives.py 883 2006-03-24 03:43:42Z willhelm $"
+
+from Pyblosxom import tools
+import time, os
+
+class PyblArchives:
+    def __init__(self, request):
+        self._request = request
+        self._archives = None
+        self._years = []
+
+    def linearArchive(self):
+        if self._archives == None:
+            self.genLinearArchive()
+        return self._archives
+        
+    def __str__(self):
+        return self.linearArchive()
+
+    def genLinearArchive(self):
+        config = self._request.getConfiguration()
+        data = self._request.getData()
+        root = config["datadir"]
+        archives = {}
+        archiveList = tools.Walk(self._request, root)
+        fulldict = {}
+        fulldict.update(config)
+        fulldict.update(data)
+      
+        month_template = config.get('archive_template_month', 
+                         '<li><a href="%(base_url)s/%(Y)s/%(b)s">%(b)s/%(Y)s</a></li>')
+        year_template = config.get('archive_template_year',
+                        '<li>%(Y)s<ul id="archive_year_contents_%(Y)s">%(month_contents)s</ul></li>')
+
+        for mem in archiveList:
+            timetuple = tools.filestat(self._request, mem)
+            timedict = {}
+            for x in ["B", "b", "m", "Y", "y"]:
+                timedict[x] = time.strftime("%" + x, timetuple)
+
+            fulldict.update(timedict)
+            if not archives.has_key(timedict['Y']):
+                archives[timedict['Y']] = {}
+            elif not archives[timedict['Y']].has_key(timedict['m']):
+                archives[timedict['Y']][timedict['m']] = (month_template % fulldict)
+
+        years = archives.keys()
+        years.sort()
+        years.reverse()
+        ordered_year_strings = []
+        
+        # store years for possible use later
+        self._years = years
+
+        # we're not done with the dictionary, so please clear it
+        for x in ["B", "b", "m", "Y", "y"]:
+            del(fulldict[x])
+        
+        for year in years:
+            month_templates = archives[year]
+            months = month_templates.keys()
+            months.sort()
+            months.reverse()
+            ordered_month_strings = []
+
+            for month in months:
+                ordered_month_strings.append(month_templates[month])
+            
+            fulldict['month_contents'] = '\n'.join(ordered_month_strings)
+            fulldict['Y'] = year
+            ordered_year_strings.append(year_template % fulldict)
+            
+        self._archives = '\n'.join(ordered_year_strings)
+
+    def linearYearlist(self):
+        config = self._request.getConfiguration()
+        template = config.get('archive_template_yearlist',
+                             'Element.hide(\'archive_year_contents_%s\');')
+        outgoing_lines = []
+        for year in self._years:
+            outgoing_lines.append(template % year)
+        return("\n".join(outgoing_lines))
+
+def cb_prepare(args):
+    request = args["request"]
+    data = request.getData()
+    archives = PyblArchives(request)
+    data["archivelinks"] = archives.linearArchive()
+    data["archiveyears"] = archives.linearYearlist()

Benjamin Mako Hill || Want to submit a patch?