diff options
-rw-r--r-- | layout/item.xml | 2 | ||||
-rwxr-xr-x | makesite.py | 9 | ||||
-rw-r--r-- | test/test_rfc_2822_date.py | 13 |
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') |