소스 검색

Make sure that modified metadata is backward compatible

Pelican <=3.3 it is a string
Pelican >3.3 it is a datetime object

Close #69
Talha Mansoor 11 년 전
부모
커밋
84ba90223e
3개의 변경된 파일51개의 추가작업 그리고 10개의 파일을 삭제
  1. 1 5
      templates/article.html
  2. 49 0
      templates/last_updated.html
  3. 1 5
      templates/page.html

+ 1 - 5
templates/article.html

@@ -83,11 +83,7 @@
             {% set day = article.date.strftime('%d')|int %}
             <time pubdate="pubdate" datetime="{{ article.date.isoformat() }}">{{ article.date.strftime('%b') }} {{ day }} {{- article.date.strftime(', %Y') }}</time>
             {% endif %}
-            {% if article.modified and article.modified != article.date %}
-            <h4>Last Updated</h4>
-            {% set day = article.modified.strftime('%d')|int %}
-            <time datetime="{{ article.modified.isoformat() }}">{{ article.modified.strftime('%b') }} {{ day }} {{- article.modified.strftime(', %Y') }}</time>
-            {% endif %}
+            {% include 'last_updated.html' %}
             {% if article.category %}
             <h4>Category</h4>
             <a class="category-link" href="{{ SITEURL }}/categories.html#{{ category.slug }}-ref">{{ article.category }}</a> 

+ 49 - 0
templates/last_updated.html

@@ -0,0 +1,49 @@
+{# code for Page and Article is exactly the same #}
+{% if article %}
+
+    {#  Check which version of Pelican user is using.
+        If it is <=3.3  than modified is a string
+        If it is >3.3 than modified is a datetime object
+    #}
+    {% if article.locale_modified and article.modified %}
+
+            {#  This check is necessary because modified is set to date by default.
+                It should be displayed only if user has explicitly set it.
+            #}
+            {% if article.modified != article.date %}
+
+            <h4>Last Updated</h4>
+            {% set day = article.modified.strftime('%d')|int %}
+            <time datetime="{{ article.modified.isoformat() }}">{{ article.modified.strftime('%b') }} {{ day }} {{- article.modified.strftime(', %Y') }}</time>
+
+            {% endif %}
+
+    {% elif article.modified %}
+
+            <h4>Last Updated</h4>
+            <div class="last-updated">{{ article.modified }}</div>
+
+    {% endif %}
+
+{# code for Page #}
+{% elif page %}
+
+    {% if page.locale_modified and page.modified %}
+
+            {% if page.modified != page.date %}
+
+            <h4>Last Updated</h4>
+            {% set day = page.modified.strftime('%d')|int %}
+            <time datetime="{{ page.modified.isoformat() }}">{{ page.modified.strftime('%b') }} {{ day }} {{- page.modified.strftime(', %Y') }}</time>
+
+            {% endif %}
+
+    {% elif page.modified %}
+
+            <h4>Last Updated</h4>
+            <div class="last-updated">{{ page.modified }}</div>
+
+    {% endif %}
+
+
+{% endif %}

+ 1 - 5
templates/page.html

@@ -46,11 +46,7 @@
             {% set day = page.date.strftime('%d')|int %}
             <time pubdate="pubdate" datetime="{{ page.date.isoformat() }}">{{ page.date.strftime('%b') }} {{ day }} {{- page.date.strftime(', %Y') }}</time>
             {% endif %}
-            {% if page.modified and page.modified != page.date %}
-            <h4>Last Updated</h4>
-            {% set day = page.modified.strftime('%d')|int %}
-            <time datetime="{{ page.modified.isoformat() }}">{{ page.modified.strftime('%b') }} {{ day }} {{- page.modified.strftime(', %Y') }}</time>
-            {% endif %}
+            {% include 'last_updated.html' %}
             {% include 'social_links.html' %}
             {% include 'mailchimp.html' %}
         </div>