* Added Preview of Blogpost in Atom/RSS Feeds
* Added feed_preview in configuration to set the length of BlogPostPreview in Lines
This commit is contained in:
Pascal Turbing 2009-12-03 22:19:56 +01:00
parent 6f50460eda
commit 6c4970adff
2 changed files with 36 additions and 9 deletions

View File

@ -9,6 +9,7 @@
# Authors: Stefan Ritter <xeno@thehappy.de>
# Adrian Vondendriesch <disco-stu@disco-stu.de>
# Pascal Turbing <pascal@turbing.de>
# Description: A simple blogging software
import cgi, os, time, glob, re, md5, sys, random, smtplib
@ -116,6 +117,9 @@ except: errorpage('"mail_to" is missing in configuration!')
try: smtp_host = configuration.get('smtp', 'smtp_host')
except: errorpage('"smtp_host" is missing in configuration!')
try: feed_preview = configuration.get('feed', 'feed_preview')
except: errorpage('"feed_preview" is missing or empty in configuration')
# Read POST Variables
action = cgi.FieldStorage()
month_display = action.getvalue('m')
@ -197,10 +201,8 @@ else:
# Generate atom feed
if feed_display == "atom":
title = str(entries[0][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '')
date = entries[0][0]
blog_title_md5sum = generate_uuid(blog_title)
title_md5sum = generate_uuid(title)
# Append 0 to the beginning if len of integer is 1 (value<10)
month = '%(#)02d' % {'#': int(date[1])}
@ -218,11 +220,25 @@ if feed_display == "atom":
print ' <id>urn:uuid:' + blog_title_md5sum + '</id>'
print ' <updated>' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z</updated>'
print ''
j = len(entries)
if j > 10: j = 10
for i in xrange(0, j):
title = str(entries[i][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '')
date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime(time.mktime(entries[i][0])))
title_md5sum = generate_uuid(title)
print ' <entry>'
print ' <title>' + title + '</title>'
print ' <link href="' + blog_url + '"/>'
print ' <link href="' + blog_url + '?p=' + title + '"/>'
print ' <id>urn:uuid:' + title_md5sum + '</id>'
print ' <updated>' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z</updated>'
print ' <updated>' + date + '</updated>'
print ' <summary>'
content = open(str(entries[i][1]), 'r')
for h in xrange(0, int(feed_preview)):
rss_line = content.readline().strip()
if rss_line != '':
print ' ' + rss_line
content.close()
print ' </summary>'
print ' </entry>'
print '</feed>'
@ -247,6 +263,14 @@ elif feed_display == "rss":
print ' <link>' + blog_url + '?p=' + title + '</link>'
print ' <guid>' + title_md5sum + '</guid>'
print ' <pubDate>' + date + '</pubDate>'
print ' <description>'
content = open(str(entries[i][1]), 'r')
for h in xrange(0, int(feed_preview)):
rss_line = content.readline().strip()
if rss_line != '':
print ' ' + rss_line
content.close()
print ' </description>'
print ' </item>'
print ' </channel>'
print '</rss>'

View File

@ -14,10 +14,13 @@ staticpages: True
monthlist: True
linklist: True
permalinks: True
comments: True
comments:
newest_first: True
[smtp]
new_comment_mail: False
mail_to: please@change.me!!!
smtp_host: localhost
[feed]
feed_preview: 10