Commit a1f4cc8d authored by Romain Bignon's avatar Romain Bignon

blog view for a single file

parent aea7391c
......@@ -29,6 +29,36 @@ from ass2m.server import ViewAction
__all__ = ['BlogPlugin']
class Post(object):
def __init__(self):
self.path = u''
self.date = None
self.title = None
self.content = None
class BlogAction(ViewAction):
def get(self):
f = self.ctx.file
post = Post()
post.path = f.get_name()
post.date = f.get_mtime()
post.title = f.get_name().replace('_', ' ') \
.lstrip('/') \
.replace('/', ' / ') \
.rsplit('.', 1)[0]
with open(f.get_realpath(), 'r') as fp:
post.content = fp.read()
if not 'html' in f.get_mimetype():
post.content = '<pre>%s</pre>' % html_escape(post.content.decode('utf-8'))
self.ctx.template_vars['categories'] = []
self.ctx.template_vars['posts'] = [post]
self.ctx.template_vars['stylesheets'].append('blog.css')
self.ctx.res.body = self.ctx.render('blog.html')
pass
class BlogListAction(ViewAction):
NB_ENTRIES = 20
......@@ -40,13 +70,6 @@ class BlogListAction(ViewAction):
def __lt__(self, o):
return self.mtime < o.mtime
class Post(object):
def __init__(self):
self.path = u''
self.date = None
self.title = None
self.content = None
def get(self):
posts = []
categories = []
......@@ -67,7 +90,7 @@ class BlogListAction(ViewAction):
if mimetype is None or not mimetype.startswith('text'):
continue
post = self.Post()
post = Post()
post.path = f.obj.path[len(self.ctx.file.path):].lstrip('/')
post.date = f.mtime
post.title = f.obj.path[len(self.ctx.file.path):].replace('_', ' ') \
......@@ -90,5 +113,8 @@ class BlogListAction(ViewAction):
class BlogPlugin(Plugin):
def init(self):
self.register_web_view(
View(object_type='directory', name='blog', public=True, verbose_name='Blog'),
View(object_type='directory', name='blog', public=False, verbose_name='Blog'),
BlogListAction, -1)
self.register_web_view(
View(object_type='file', name='blog', public=False, verbose_name='Blog'),
BlogAction, -1)
......@@ -32,4 +32,7 @@ div.post_content {
padding: 10px;
}
div.post_content blockquote {
border-left: 3px solid #CCCCCC;
padding-left: 5px;
}
......@@ -16,7 +16,7 @@
<section>
% for post in posts:
<div class="post">
<h2 class="post_title"><a href="${URL(post.path) | n,U,h}">${post.title | h}</a></h2>
<h2 class="post_title"><a href="${URL(post.path).setvar(view='blog') | n,U,h}">${post.title | h}</a></h2>
<span class="post_meta">Written at <time datetime="${post.date.strftime('%Y-%m-%dT%H:%M') | h}">${post.date.strftime('%Y-%m-%d %H:%M:%S') | h}</time></span>
<div class="post_content">
${post.content}
......@@ -29,7 +29,7 @@
<%def name="title(html=False)" filter="cpt">
% if html:
Blog of ${partials.breadcrumbs(path)}
Blog of ${partials.breadcrumbs(path, isdir=file.isdir())}
% else:
Blog of ${path}/
% endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment