From 6c4970adff15fe709a25c559501678ad4dde44d3 Mon Sep 17 00:00:00 2001 From: Pascal Turbing Date: Thu, 3 Dec 2009 22:19:56 +0100 Subject: Feeds: * Added Preview of Blogpost in Atom/RSS Feeds * Added feed_preview in configuration to set the length of BlogPostPreview in Lines --- blogthon.cgi | 40 ++++++++++++++++++++++++++++++++-------- configuration | 5 ++++- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/blogthon.cgi b/blogthon.cgi index 714948f..48a9dee 100755 --- a/blogthon.cgi +++ b/blogthon.cgi @@ -9,6 +9,7 @@ # Authors: Stefan Ritter # Adrian Vondendriesch +# Pascal Turbing # 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,12 +220,26 @@ if feed_display == "atom": print ' urn:uuid:' + blog_title_md5sum + '' print ' ' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z' print '' - print ' ' - print ' ' + title + '' - print ' ' - print ' urn:uuid:' + title_md5sum + '' - print ' ' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z' - 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 ' ' + print ' ' + title + '' + print ' ' + print ' urn:uuid:' + title_md5sum + '' + print ' ' + date + '' + print ' ' + 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 ' ' + print ' ' print '' # Generate rss 2.0 feed @@ -247,6 +263,14 @@ elif feed_display == "rss": print ' ' + blog_url + '?p=' + title + '' print ' ' + title_md5sum + '' print ' ' + date + '' + print ' ' + 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 ' ' print ' ' print ' ' print '' diff --git a/configuration b/configuration index c7b3a2a..234f1ed 100644 --- a/configuration +++ b/configuration @@ -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 -- cgit v1.2.3