changeset 120:e2df85f9b23d

Don't turn some meta properties (like `redirect` or `title`) into arrays.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 19 Nov 2013 23:07:50 -0800
parents 013c531733cc
children 7c7f7eca51ae
files wikked/formatter.py wikked/page.py
diffstat 2 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/wikked/formatter.py	Tue Nov 19 23:06:57 2013 -0800
+++ b/wikked/formatter.py	Tue Nov 19 23:07:50 2013 -0800
@@ -5,6 +5,9 @@
 from utils import get_meta_name_and_modifiers, html_escape
 
 
+SINGLE_METAS = ['redirect', 'title']
+
+
 class BaseContext(object):
     """ Base context for formatting pages. """
     def __init__(self, url):
@@ -66,10 +69,15 @@
 
             # Then, set the value on the meta dictionary, or add it to
             # other existing meta values with the same key.
-            if meta_name not in ctx.meta:
-                ctx.meta[meta_name] = [coerced_meta_value]
+            # TODO: right now we have a hard-coded list of meta names we know
+            #       shouldn't be made into an array... make it configurable.
+            if meta_name in SINGLE_METAS:
+                ctx.meta[meta_name] = coerced_meta_value
             else:
-                ctx.meta[meta_name].append(coerced_meta_value)
+                if meta_name not in ctx.meta:
+                    ctx.meta[meta_name] = [coerced_meta_value]
+                else:
+                    ctx.meta[meta_name].append(coerced_meta_value)
 
             # Process it, or remove it from the output text.
             if clean_meta_name in self.processors:
@@ -182,7 +190,6 @@
         current = ''
         env = jinja2.Environment()
         for token in env.lex(text):
-            lineno = token[0]
             token_type = token[1]
             value = token[2]
             if token_type == 'data':
--- a/wikked/page.py	Tue Nov 19 23:06:57 2013 -0800
+++ b/wikked/page.py	Tue Nov 19 23:07:50 2013 -0800
@@ -3,7 +3,7 @@
 import re
 import datetime
 import jinja2
-from formatter import PageFormatter, FormattingContext
+from formatter import PageFormatter, FormattingContext, SINGLE_METAS
 from resolver import PageResolver, CircularIncludeError
 
 
@@ -201,7 +201,7 @@
         # Add some common meta.
         data.title = re.sub(r'\-', ' ', filename_split[0])
         if 'title' in data.local_meta:
-            data.title = data.local_meta['title'][0]
+            data.title = data.local_meta['title']
 
         return data
 
@@ -274,10 +274,13 @@
         data.local_meta = {}
         for m in db_obj.meta:
             value = data.local_meta.get(m.name)
-            if value is None:
-                data.local_meta[m.name] = [m.value]
+            if m.name in SINGLE_METAS:
+                data.local_meta[m.name] = m.value
             else:
-                data.local_meta[m.name].append(m.value)
+                if value is None:
+                    data.local_meta[m.name] = [m.value]
+                else:
+                    data.local_meta[m.name].append(m.value)
 
         data.local_links = [l.target_url for l in db_obj.links]