Reunite UTF-8 hack comment with sys.setdefaultencoding call it labels.
[cookbook.git] / cookbook / server.py
index 99dba5eaf85175e3939f7af0be4b48b46c5d010e..e94e7693e95977d03441d8e6b424ceafd82eb799 100644 (file)
@@ -25,6 +25,7 @@ import os
 import random
 import re
 import types
+from urllib import urlencode
 import uuid
 from xml.sax import saxutils
 
@@ -82,8 +83,12 @@ class Server (object):
             recipe = random.choice(self.cookbook)
         else:
             recipe = self.cookbook.index[name]
+        tag_links = [
+            '<a href="./?%s">%s</a>' % (urlencode({'tag':t}), t)
+            for t in (recipe.tags or [])]
         template = self.env.get_template('recipe.html')
-        return template.render(cookbook=self.cookbook, recipe=recipe)
+        return template.render(cookbook=self.cookbook, recipe=recipe,
+                               tag_links=tag_links)
 
     @cherrypy.expose
     def add_tag(self, name, tag):
@@ -160,6 +165,7 @@ class Server (object):
             print 'new'
             self.cookbook.append(recipe)
             self.cookbook.make_index()
+            self.cookbook.sort(key=lambda r: r.path)
         elif name != recipe.name:  # renamed recipe
             print 'rename'
             os.remove(recipe.path)