Browse Source

Have Dateish support multiple dates per field

Kernc 9 years ago
parent
commit
eeb79b8376
2 changed files with 15 additions and 8 deletions
  1. 10 5
      dateish/Readme.rst
  2. 5 3
      dateish/dateish.py

+ 10 - 5
dateish/Readme.rst

@@ -13,11 +13,13 @@ For example, if you have the following pieces of metadata in an article:
 
     # my_article.markdown
     Date: 2000-01-01
-    Created_Date: 1999-08-04
     Idea_Date: 1993-03-04
+    Important_Dates: 2013-10-12
+                     2013-11-08
+                     2013-12-02
 
-Normally, the Created_Date and Idea_Date variables will be strings, so you will
-not be able to use the strftime() Jinja filter on them.
+Normally, the Idea_Date and Important_Dates variables will be strings, so
+you will not be able to use the strftime() Jinja filter on them.
 
 With this plugin, you define in your settings file a list of the names of
 the additional metadata fields you want to treat as dates:
@@ -25,12 +27,15 @@ the additional metadata fields you want to treat as dates:
 .. code-block:: python
 
     # pelicanconf.py
-    DATEISH_PROPERTIES = ['created_date', 'idea_date']
+    DATEISH_PROPERTIES = ['idea_date', 'important_dates']
 
 Then you can use them in templates just like date:
 
 .. code-block:: html+jinja
 
     # mytemplate.html
-    <p>Created date: {{ article.created_date | strftime('%d %B %Y') }}</p>
+    <p>Idea date: {{ article.idea_date | strftime('%d %B %Y') }}</p>
+    {% for d in article.important_dates %}
+        <p>Important date: {{ d | strftime('%d %B %Y') }}</p>
+    {% endfor %}
 

+ 5 - 3
dateish/dateish.py

@@ -18,9 +18,11 @@ def dateish(generator):
     for article in generator.articles:
         for field in generator.settings['DATEISH_PROPERTIES']:
             if hasattr(article, field):
-                text = getattr(article, field)
-                as_datetime = get_date(text)
-                setattr(article, field, as_datetime)
+                value = getattr(article, field)
+                if type(value) == list:
+                    setattr(article, field, [get_date(d) for d in value])
+                else:
+                    setattr(article, field, get_date(value))
 
 def register():
     signals.article_generator_finalized.connect(dateish)