Re: yeararchives (2)

"Sebastian Spaeth" <[email protected]> Wed, 05 May 2010 08:45:55 +0200
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
On 2010-05-04, Sebastian Spaeth wrote:
> Separately, I am going to send a patch that implements the
> cb_staticrender_filelist callback for the yeararchives plugin.

Done that now. Is it the right way to render "2003.snarfed" "2003.html"
(all static_flavours and all years) rather than simply "2003" ?

This patch in itself won't solve all problems though, as the yearmonths
plugin currently understands /2003?flav=html but not /2003.html. That
will need  fixing too, but this provides the necessary infrastructure already.

Let me know if this looks good and should be pushed or reworked.

Sebastian

Commit 749e57d386cd2662d9a20f29e833caa66f85f26c in branch
"yearmonth-staticfilelist" in my gitorious repository:
------------8<------------------8<------------------8<------------------8<----
yeararchives: Implement cb_staticrender_filelist
    
The yeararchives plugin can offer a filelist to be rendered via the
cb_staticrender_filelist callback. This allows us to automatically
render all needed archive pages. We render all static flavours. If
static flavors are "html" and "snarfed", this leads to the URLs
"2003.snarfed" "2003.html" "2004.snarfed" "2004.html" etc.
    
Do note that the yearmonths plugin can currently not cope with .flavor
endings yet, so rendering these URLS currently leads to 404 pages.

diff --git a/plugins/archives/yeararchives.py b/plugins/archives/yeararchives.py
index d558462..60b9065 100644
--- a/plugins/archives/yeararchives.py
+++ b/plugins/archives/yeararchives.py
@@ -149,6 +149,39 @@ def new_entry(request, yearmonth, body):
 
 INIT_KEY = "yeararchives_initiated"
 
+def cb_staticrender_filelist(args):
+    """ Offers a list of archivelinks that we want to render.
+
+    When we render statically nobody knows which URLs this plugin wants to render.
+    This parsers all files and adds all URLs that we want to render. It is
+    perhaps not the most efficient way as we will reparse all files later again.
+    But as this only happens on static rendering which is not that time critical,
+    we should be on the safe side here.
+    
+    :param: args is a dict that contains: request, filelist, flavours.
+            Request is the request object, filelist a list of (URL,"") tuples
+            that we want to render and flavours the list of flavours that
+            we are supposed to render.
+    """
+    request = args["request"]
+    filelist = args["filelist"]
+    flavours = args["flavours"]
+    config = request.get_configuration()
+    root = config["datadir"]
+
+    archive_list = tools.walk(request, root)
+    years = set()
+
+    # go through all timestamps of all posts, extracting the years
+    for mem in archive_list:
+        timetuple = tools.filestat(request, mem)
+        years.add(timetuple[0])
+
+    for f in flavours:
+        for year in years:
+            filelist.append(('/' + str(year) + '.' + f, ""))
+    
+
 def cb_prepare(args):
     request = args["request"]
     data = request.get_data()

------------------------------------------------------------------------------

_______________________________________________
Pyblosxom-devel mailing list
Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkvhFCMACgkQVYX1jMgnoGKDZACfZeapZ2TIOGFxbsxV1aYzxjzg
lMAAn2PyE+OrUsROqBbAhY45FX+haMB5
=HK0a
-----END PGP SIGNATURE-----