Make permalinks more search engine friendly
authorBernardo Innocenti <bernie@codewiz.org>
Sat, 22 Mar 2008 16:25:44 +0000 (17:25 +0100)
committerBernardo Innocenti <bernie@codewiz.org>
Fri, 28 Mar 2008 08:36:21 +0000 (09:36 +0100)
geekigeeki.py

index 76888601650f52e137b24a9278cbf9c5c12aad04..cf69d55e013c25335643290af2dde44b8820f91a 100755 (executable)
@@ -70,8 +70,10 @@ def relative_url(pathname, privileged=False):
         pathname = url + '/' + pathname
     return pathname
 
-# Formatting stuff --------------------------------------------------
+def permalink(s):
+    return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip())
 
+# Formatting stuff --------------------------------------------------
 def emit_header(mime_type="text/html"):
     print "Content-type: " + mime_type + "; charset=utf-8\n"
 
@@ -360,8 +362,8 @@ class PageFormatter:
             self.h_level = 0
         else:
             self.h_level = len(word) - 1
-            abridged = re.sub('[^A-Za-z0-9_]', '', self.line).lower()
-            result = '\n</p><h%d id="%s"><a class="heading" href="#%s">¶</a> ' % (self.h_level, abridged, abridged)
+            link = permalink(self.line)
+            result = '<h%d id="%s"><a class="heading" href="#%s">¶</a> ' % (self.h_level, link, link)
         return result
 
     def _br_repl(self, word):