söndag 22 aug 2004

Allow metadata in textile entries

This patch allows for metadata entries in .txtl files.

Example metadata:

title
#metakey metavalue
entry body text

The patch looks like this:

--- pyblosxom/contrib/entryparsers/txtl.py~     2004-05-19 11:51:35.000000000 +0200
+++ pyblosxom/contrib/entryparsers/txtl.py      2004-08-16 17:51:49.000000000 +0200
@@ -190,11 +190,22 @@
 
 def readfile(filename, request):
     entryData = {}
-    d = open(filename).read()
+    d = open(filename).readlines()
 
-    # Grab title and body.
-    title = d.split('\n')[0]
-    body  = d[len(title):]
+    # Grab title
+    entryData['title'] = d.pop(0).strip()
+
+    # this handles properties of the entry that are between
+    # the title and the body and start with a #
+    import re
+    while len(d) > 0:
+        match = re.match(r'^#(\w+)\s+(.*)', d[0])
+        if match:
+            d.pop(0)
+            entryData[match.groups()[0]] = match.groups()[1].strip()
+        else:
+            break
+    body = "\n" + ''.join(d)
 
     # Grab textile configuration.
     config = request.getConfiguration()
@@ -205,8 +216,7 @@
     
     body = textile(body, head_offset=head_offset, validate=validate, output=output, encoding=encoding)
 
-    entryData = {'title': title,
-                 'body': body}
+    entryData['body'] = body
 
     # Call the postformat callbacks
     tools.run_callback('postformat',

The code is based on the standard pyblosxom entry parser for .txt-files.

xhtml plugin for pyblosxom

I wanted pyblosxom to send application/xhtml+xml to browsers that claim to support it so I whipped together a pyblosxom-plugin to do it.

I needed to modify two files from pyblosxom too. First the cgi, pyblosxom.cgi to make it recognize HTTP_ACCEPT:

--- pyblosxom/web/pyblosxom.cgi~        2004-05-04 22:53:48.000000000 +0200
+++ pyblosxom/web/pyblosxom.cgi 2004-08-22 14:02:31.000000000 +0200
@@ -34,7 +34,8 @@
     d = {}
     for mem in ["HTTP_HOST", "HTTP_USER_AGENT", "HTTP_REFERER", "PATH_INFO", 
             "QUERY_STRING", "REMOTE_ADDR", "REQUEST_METHOD", "REQUEST_URI", 
-            "SCRIPT_NAME", "HTTP_IF_NONE_MATCH", "HTTP_IF_MODIFIED_SINCE"]:
+            "SCRIPT_NAME", "HTTP_IF_NONE_MATCH", "HTTP_IF_MODIFIED_SINCE",
+            "HTTP_ACCEPT"]:
         d[mem] = os.environ.get(mem, "")
     req.addHttp(d)

I also needed to modify the default renderer to not escape the body of entries:

--- pyblosxom/Pyblosxom/renderers/blosxom.py~   2004-05-28 02:55:08.000000000 +0200
+++ pyblosxom/Pyblosxom/renderers/blosxom.py    2004-08-22 13:01:55.000000000 +0200
@@ -125,7 +125,7 @@
 
         output = []
 
-        if data["content-type"].endswith("xml"):
+        if data["content-type"].endswith("/xml"):
             quotes = {"'": "'", '"': """}
             entry['title'] = escape(entry['title'],quotes)
             entry.setData(escape(entry.getData(),quotes))

The plugin itself can be downloaded here

copyright © 1999-2008 Ludvig Omholt | min publika pgpnyckel | version 4.0 (r1109M) using pyblosxom 1.1 RC1
stargirl.org - moderskeppet Valid XHTML 1.0! Valid CSS! RSS Feed
Dumma robotar kan skicka sin skräppost för automatisk klassificering hit: honung@ludde.net