summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunaina Pai <sunainapai.in@gmail.com>2018-06-16 16:18:57 +0530
committerSunaina Pai <sunainapai.in@gmail.com>2018-06-16 16:18:57 +0530
commit99c8e268a6c2c75943e1069ff95a5d64e1e19908 (patch)
tree91f5ec5c4e89f60b440d2862317f5f578bcc0758
parent6c0d374ff14bbe76c8af7e585c8fecd26f25e912 (diff)
Use RFC 2822 format date in RSS feeds
-rw-r--r--layout/item.xml2
-rwxr-xr-xmakesite.py9
-rw-r--r--test/test_rfc_2822_date.py13
3 files changed, 22 insertions, 2 deletions
diff --git a/layout/item.xml b/layout/item.xml
index 65b9679..8403e00 100644
--- a/layout/item.xml
+++ b/layout/item.xml
@@ -9,5 +9,5 @@
<p><a href="{{ site_url }}/{{ blog }}/{{ slug }}/">Read More</a></p>
]]>
</description>
-<pubDate>{{ date }}</pubDate>
+<pubDate>{{ rfc_2822_date }}</pubDate>
</item>
diff --git a/makesite.py b/makesite.py
index ce1c9b3..8f4c736 100755
--- a/makesite.py
+++ b/makesite.py
@@ -70,6 +70,12 @@ def read_headers(text):
yield match.group(1), match.group(2), match.end()
+def rfc_2822_format(date_str):
+ """Convert yyyy-mm-dd date string to RFC 2822 format date string."""
+ d = datetime.datetime.strptime(date_str, '%Y-%m-%d')
+ return d.strftime('%a, %d %b %Y %H:%M:%S +0000')
+
+
def read_content(filename):
"""Read content and metadata from file into a dictionary."""
# Read file content.
@@ -101,10 +107,11 @@ def read_content(filename):
except ImportError as e:
log('WARNING: Cannot render Markdown in {}: {}', filename, str(e))
- # Update the dictionary with content text and summary text.
+ # Update the dictionary with content, summary, and RFC 2822 date.
content.update({
'content': text,
'summary': truncate(text),
+ 'rfc_2822_date': rfc_2822_format(content['date'])
})
return content
diff --git a/test/test_rfc_2822_date.py b/test/test_rfc_2822_date.py
new file mode 100644
index 0000000..db9970f
--- /dev/null
+++ b/test/test_rfc_2822_date.py
@@ -0,0 +1,13 @@
+import unittest
+import makesite
+
+
+class RFC822DateTest(unittest.TestCase):
+
+ def test_epoch(self):
+ self.assertEqual(makesite.rfc_2822_format('1970-01-01'),
+ 'Thu, 01 Jan 1970 00:00:00 +0000')
+
+ def test_2018_06_16(self):
+ self.assertEqual(makesite.rfc_2822_format('2018-06-16'),
+ 'Sat, 16 Jun 2018 00:00:00 +0000')