2015-02-26 20:26:39 +01:00
|
|
|
#!/usr/bin/env python2
|
2015-02-26 23:56:19 +01:00
|
|
|
import os
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
import markdown
|
2015-02-26 20:26:39 +01:00
|
|
|
|
|
|
|
from verdandi.mixins.templatemixin import TemplateMixin
|
|
|
|
from verdandi.mixins.menuitemmixin import MenuItemMixin
|
2016-04-23 00:15:49 +02:00
|
|
|
from verdandi.mixins.fileassetsmixin import FileAssetsMixin
|
2016-01-23 02:45:22 +01:00
|
|
|
from verdandi.mixins.newsitemmixin import NewsItemMixin
|
2017-04-25 21:33:46 +02:00
|
|
|
from verdandi.mixins.metadatamixin import MetadataMixin
|
2016-01-22 00:10:32 +01:00
|
|
|
from verdandi.constants import CONTENT_DIRECTORY, MARKDOWN_EXTENSIONS
|
2015-02-26 20:26:39 +01:00
|
|
|
|
2017-04-25 21:33:46 +02:00
|
|
|
class Page(MenuItemMixin, NewsItemMixin, MetadataMixin, TemplateMixin, FileAssetsMixin):
|
2015-02-26 23:56:19 +01:00
|
|
|
|
|
|
|
content_file = "content.md"
|
2016-04-20 21:09:34 +02:00
|
|
|
content_is_markdown = True
|
2015-02-26 23:56:19 +01:00
|
|
|
content_directory = CONTENT_DIRECTORY
|
|
|
|
|
2016-01-22 00:10:32 +01:00
|
|
|
markdown_extensions = MARKDOWN_EXTENSIONS
|
|
|
|
|
2016-01-23 02:45:22 +01:00
|
|
|
news_item_len = 10
|
2017-04-25 21:33:46 +02:00
|
|
|
metadata_description_len = 10
|
2016-01-23 02:45:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
def process_message(self, message):
|
|
|
|
if message == None:
|
|
|
|
full_path = os.path.join(self.content_directory, self.content_file)
|
|
|
|
self.content = self.read_content_file(full_path)
|
|
|
|
|
|
|
|
other_messages = super(Page, self).process_message(message)
|
|
|
|
|
|
|
|
return other_messages
|
|
|
|
|
|
|
|
|
|
|
|
def get_news_item(self):
|
|
|
|
lines = self.content['content'].split('\n')
|
|
|
|
elipsized_content = '\n'.join(lines[0:self.news_item_len])
|
|
|
|
|
|
|
|
item = {
|
2016-11-14 23:39:58 +01:00
|
|
|
'title': self.content['title'],
|
2016-01-23 02:45:22 +01:00
|
|
|
'content': elipsized_content,
|
|
|
|
'creation_time': self.content['creation_time'],
|
|
|
|
'edit_time': self.content['edit_time'],
|
|
|
|
'url' : self.url
|
|
|
|
}
|
|
|
|
|
|
|
|
return item
|
|
|
|
|
2017-04-25 21:33:46 +02:00
|
|
|
def get_metadata(self):
|
|
|
|
markdown_converter = markdown.Markdown(extensions = self.markdown_extensions)
|
|
|
|
|
|
|
|
metadata = super(Page, self).get_metadata()
|
|
|
|
lines = self.content['content'].split('\n')
|
|
|
|
elipsized_content = '\n'.join(lines[0:self.news_item_len])
|
|
|
|
elipsized_content = markdown_converter.convert(elipsized_content)
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
'url': "/%s" % self.url,
|
|
|
|
'title': self.content['title'],
|
|
|
|
'description' : elipsized_content
|
|
|
|
}
|
|
|
|
|
|
|
|
if 'image' in metadata:
|
|
|
|
meta['image'] = "/%s" % metadata['image']
|
|
|
|
|
|
|
|
return meta
|
2015-02-26 20:26:39 +01:00
|
|
|
|
|
|
|
def get_context(self):
|
|
|
|
context = super(Page,self).get_context()
|
2016-11-14 23:39:58 +01:00
|
|
|
context['title'] = self.content['title']
|
2016-11-16 01:10:29 +01:00
|
|
|
context['url'] = "/%s" % self.url
|
2015-02-26 20:26:39 +01:00
|
|
|
|
2016-01-23 02:45:22 +01:00
|
|
|
context['content_creation_time'] = self.content['creation_time']
|
|
|
|
context['content_edit_time'] = self.content['edit_time']
|
2015-02-26 23:56:19 +01:00
|
|
|
|
2016-04-20 21:09:34 +02:00
|
|
|
if self.content_is_markdown:
|
|
|
|
markdown_converter = markdown.Markdown(extensions = self.markdown_extensions)
|
|
|
|
markdown_source = self.content['content']
|
|
|
|
context['content'] = markdown_converter.convert(markdown_source)
|
|
|
|
else:
|
|
|
|
context['content'] = self.content['content']
|
2015-02-26 23:56:19 +01:00
|
|
|
|
|
|
|
return context
|