X-Git-Url: https://git.llucax.com/software/blitiri.git/blobdiff_plain/5e45cd0354881aee35f582b4c233eb8341ebc7a3..7d653403b505dc4de30d1e7026922e9e144c77d6:/blitiri.cgi diff --git a/blitiri.cgi b/blitiri.cgi index 1dadce5..79e4171 100755 --- a/blitiri.cgi +++ b/blitiri.cgi @@ -14,6 +14,12 @@ # Directory where entries are stored data_path = "/tmp/blog/data" +# Are comments allowed? (if False, comments_path option is not used) +enable_comments = False + +# Directory where comments are stored (must be writeable by the web server) +comments_path = "/tmp/blog/comments" + # Path where templates are stored. Use an empty string for the built-in # default templates. If they're not found, the built-in ones will be used. templates_path = "/tmp/blog/templates" @@ -42,6 +48,8 @@ encoding = "utf8" import sys import os +import errno +import shutil import time import datetime import calendar @@ -60,17 +68,22 @@ except: pass +# Pimp *_path config variables to support relative paths +data_path = os.path.realpath(data_path) +templates_path = os.path.realpath(templates_path) + # Default template -default_main_header = """ - +default_main_header = """\ + + - +
- +"
- raw = raw[raw.index('\n'):]
-
- settings = {
- 'input_encoding': encoding,
- 'output_encoding': 'utf8',
+ return rst_to_html(self.raw_content)
+
+ def to_vars(self):
+ return {
+ 'arttitle': sanitize(self.title),
+ 'author': sanitize(self.author),
+ 'date': self.created.isoformat(' '),
+ 'uuid': self.uuid,
+ 'tags': self.get_tags_links(),
+ 'comments': len(self.comments),
+
+ 'created': self.created.isoformat(' '),
+ 'ciso': self.created.isoformat(),
+ 'cyear': self.created.year,
+ 'cmonth': self.created.month,
+ 'cday': self.created.day,
+ 'chour': self.created.hour,
+ 'cminute': self.created.minute,
+ 'csecond': self.created.second,
+
+ 'updated': self.updated.isoformat(' '),
+ 'uiso': self.updated.isoformat(),
+ 'uyear': self.updated.year,
+ 'umonth': self.updated.month,
+ 'uday': self.updated.day,
+ 'uhour': self.updated.hour,
+ 'uminute': self.updated.minute,
+ 'usecond': self.updated.second,
}
- parts = publish_parts(self.raw_content,
- settings_overrides = settings,
- writer_name = "html")
- return parts['body'].encode('utf8')
def get_tags_links(self):
l = []
@@ -412,11 +741,11 @@ class Article (object):
tags.sort()
for t in tags:
l.append('%s' % \
- (blog_url, urllib.quote(t), t) )
+ (blog_url, urllib.quote(t), sanitize(t) ))
return ', '.join(l)
-class DB (object):
+class ArticleDB (object):
def __init__(self, dbpath):
self.dbpath = dbpath
self.articles = []
@@ -456,11 +785,9 @@ class DB (object):
except:
continue
- a = Article(l[0])
- a.created = datetime.datetime.fromtimestamp(
- float(l[1]) )
- a.updated = datetime.datetime.fromtimestamp(
- float(l[2]))
+ a = Article(l[0],
+ datetime.datetime.fromtimestamp(float(l[1])),
+ datetime.datetime.fromtimestamp(float(l[2])))
self.uuids[a.uuid] = a
self.actyears.add(a.created.year)
self.actmonths.add((a.created.year, a.created.month))
@@ -501,14 +828,29 @@ class DB (object):
#
-def render_html(articles, db, actyear = None):
+def render_html(articles, db, actyear = None, show_comments = False,
+ redirect = None):
+ if redirect is not None:
+ print 'Status: 303 See Other\r\n',
+ print 'Location: %s\r\n' % redirect,
+ print 'Content-type: text/html; charset=utf-8\r\n',
+ print '\r\n',
template = Templates(templates_path, db, actyear)
- print 'Content-type: text/html; charset=utf-8\n'
print template.get_main_header()
for a in articles:
print template.get_article_header(a)
print a.to_html()
print template.get_article_footer(a)
+ if show_comments:
+ print ''
+ for c in a.comments:
+ if c is None:
+ continue
+ print template.get_comment_header(c)
+ print c.to_html()
+ print template.get_comment_footer(c)
+ print template.get_comment_form(a, 'post',
+ blog_url + '/comment/' + a.uuid)
print template.get_main_footer()
def render_artlist(articles, db, actyear = None):
@@ -548,6 +890,11 @@ def render_atom(articles):
}
for a in articles:
+ vars = a.to_vars()
+ vars.update( {
+ 'url': full_url,
+ 'contents': a.to_html(),
+ } )
print """
%(contents)s
Comment #%(number)d
+by %(author)s + on %(year)04d-%(month)02d-%(day)02d %(hour)02d:%(minute)02d + +