diff --git a/requirements.txt b/requirements.txt index 746480b..2c04e1d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Jinja2==2.7.3 Markdown==2.6 MarkupSafe==0.23 +python-dateutil==2.4.2 +six==1.10.0 diff --git a/test_input/content/content.md b/test_input/content/content.md index 062d6c1..f5f27e5 100644 --- a/test_input/content/content.md +++ b/test_input/content/content.md @@ -1,3 +1,6 @@ +12.2.2014 13:37 +12.2.2014 23:42 + Test ---- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. diff --git a/test_input/content/news/test.md b/test_input/content/news/test.md index 0255835..9b39eb1 100644 --- a/test_input/content/news/test.md +++ b/test_input/content/news/test.md @@ -1,3 +1,6 @@ +1.1.2016 12:00 +22.1.2016 17:00 + First test ========== This is a first test newsitem diff --git a/test_input/content/news/test1.md b/test_input/content/news/test1.md index 0dcdf9e..9355611 100644 --- a/test_input/content/news/test1.md +++ b/test_input/content/news/test1.md @@ -1,3 +1,6 @@ +15.1.2016 12:00 +22.1.2016 17:00 + Second test ========== This is an other test newsitem diff --git a/verdandi/mixins/templatemixin.py b/verdandi/mixins/templatemixin.py index 3a14570..82ca72f 100644 --- a/verdandi/mixins/templatemixin.py +++ b/verdandi/mixins/templatemixin.py @@ -2,6 +2,8 @@ import os +from dateutil import parser + class TemplateMixin(object): template = "base.html" url = "index.html" @@ -30,3 +32,19 @@ class TemplateMixin(object): out_file = open(out_path, "wb") out_file.write(result) out_file.close() + + + def read_content_file(self, path): + content_file = open(path, 'r') + + result = {} + + first_line = content_file.readline() + second_line = content_file.readline() + + result['content'] = content_file.read() + + result['creation_time'] = parser.parse(first_line) + result['edit_time'] = parser.parse(second_line) + + return result diff --git a/verdandi/modules/newsfeed.py b/verdandi/modules/newsfeed.py index 1269797..4832940 100644 --- a/verdandi/modules/newsfeed.py +++ b/verdandi/modules/newsfeed.py @@ -55,14 +55,9 @@ class NewsFeed(MenuItemMixin, TemplateMixin, AssetsMixin): full_path = os.path.join(item_directory, news_file) - ctime = os.path.getctime(full_path) - item['creation_time'] = datetime.fromtimestamp(ctime) + item = self.read_content_file(full_path) - mtime = os.path.getmtime(full_path) - item['edit_time'] = datetime.fromtimestamp(mtime) - - markdown_source = open(full_path, 'r').read() - item['content'] = markdown_converter.convert(markdown_source) + item['content'] = markdown_converter.convert(item['content']) print item diff --git a/verdandi/modules/page.py b/verdandi/modules/page.py index 7e1a357..57c2038 100644 --- a/verdandi/modules/page.py +++ b/verdandi/modules/page.py @@ -25,13 +25,12 @@ class Page(MenuItemMixin, TemplateMixin, AssetsMixin): full_path = os.path.join(self.content_directory, self.content_file) markdown_converter = markdown.Markdown(extensions = self.markdown_extensions) - ctime = os.path.getctime(full_path) - context['content_creation_time'] = datetime.fromtimestamp(ctime) + content = self.read_content_file(full_path) - mtime = os.path.getmtime(full_path) - context['content_edit_time'] = datetime.fromtimestamp(mtime) + context['content_creation_time'] = content['creation_time'] + context['content_edit_time'] = content['edit_time'] - markdown_source = open(full_path, 'r').read() + markdown_source = content['content'] context['content'] = markdown_converter.convert(markdown_source) return context diff --git a/verdandi/verdandi.py b/verdandi/verdandi.py index b2db4f0..25e1e95 100644 --- a/verdandi/verdandi.py +++ b/verdandi/verdandi.py @@ -58,5 +58,5 @@ class Verdandi(object): if len(sys.argv) > 1 and sys.argv[1] == 'serve': os.chdir(self.output_directory) - httpd = SocketServer.TCPServer(("", SERVE_PORT), SimpleHTTPRequestHandler) + httpd = SocketServer.TCPServer(("0.0.0.0", SERVE_PORT), SimpleHTTPRequestHandler) httpd.serve_forever()