Added proper handling for file metadata

Fixes #1
This commit is contained in:
Sebastian 2016-01-22 01:17:28 +01:00
parent 87c00ae761
commit 843463b548
8 changed files with 36 additions and 13 deletions

View File

@ -1,3 +1,5 @@
Jinja2==2.7.3
Markdown==2.6
MarkupSafe==0.23
python-dateutil==2.4.2
six==1.10.0

View File

@ -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.

View File

@ -1,3 +1,6 @@
1.1.2016 12:00
22.1.2016 17:00
First test
==========
This is a first test newsitem

View File

@ -1,3 +1,6 @@
15.1.2016 12:00
22.1.2016 17:00
Second test
==========
This is an other test newsitem

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()