From 6bfd0d4bdea4265b1748b7ecee67183caf7707f3 Mon Sep 17 00:00:00 2001 From: Stefan Ritter Date: Tue, 24 Mar 2009 20:37:21 +0100 Subject: * Added a first FAQ * Added atom feeds --- FAQ | 5 + blogthon.cgi | 340 +++++++++++++++++++++++++++++++++-------------------------- 2 files changed, 198 insertions(+), 147 deletions(-) create mode 100644 FAQ diff --git a/FAQ b/FAQ new file mode 100644 index 0000000..3a88302 --- /dev/null +++ b/FAQ @@ -0,0 +1,5 @@ +1) I edited an entry, now it is listed first on the page... wtf? + + Unix don't know a creation time for a file, so i had to use the last + changed time for entries. You can use 'touch' to edit the timestamp. + Syntax is 'touch foo.txt -t YYMMDDhhmm'. diff --git a/blogthon.cgi b/blogthon.cgi index 2acc7f5..983aa99 100755 --- a/blogthon.cgi +++ b/blogthon.cgi @@ -15,6 +15,7 @@ import time import glob import re import ConfigParser +import md5 configuration = ConfigParser.ConfigParser() configuration.read('configuration') @@ -38,10 +39,12 @@ month_display = action.getvalue('m') post_display = action.getvalue('p') static_display = action.getvalue('s') allentries_display = action.getvalue('a') +feed_display = action.getvalue('feed') if not month_display: month_display = "" if not post_display: post_display = "" if not static_display: static_display = "" if not allentries_display: allentries_display = "" +if not feed_display: feed_display = "" # Commentstuff ctitle = action.getvalue('ctitle') @@ -75,20 +78,7 @@ if cname and ctext and ctitle: content.write("." + line + "\n") content.close() -print 'Content-type: text/html\n' -print '' -print '' -print ' ' -print ' ' + blog_title + '' -print ' ' -print ' ' -print ' ' -print ' ' -print ' ' -print ' ' -print '
' + blog_title + '
' - +# Read entries and store their title and timestamp entries = [] entries_list = glob.glob(entries_dir + '*.' + entries_suffix) @@ -103,139 +93,195 @@ if newest_first: else: entries.sort() -print '
' -print '
' - -if static_display != "": # Show Staticpage - content = open(staticpages_dir + static_display, "r") - print '
' + re.sub('\d+?-', '', static_display) + '
' - print '

' - for line in content: - print ' ' + line.strip() + '
' - print '

' - content.close() -else: # Show regular entry - entry_counter = 0 - for entry in entries: - date = time.strftime("%c", entry[0]) - date_to_compare = time.strftime("%m%Y", entry[0]) # Needed for permalinks - entry = entry[1] - title = entry.replace('entries/', '', 1) - title = title.replace('.txt', '') - - if month_display == date_to_compare or not month_display: - if post_display == title or not post_display: - if allentries_display == "1" or entry_counter < entries_per_page: - content = open(entry, "r") - if permalinks: # Title as permalink... - print ' ' - else: # ... or not - print '
' + title + ' (' + date + ')
' - print '
' - for line in content: - print ' ' + line.strip() + '
' - - # Comments are shown when post_display and comments_file - comments_file = glob.glob(entries_dir + title + '.comments') - if post_display: - if comments_file: - print '

' - comments_file = glob.glob(entries_dir + title + '.comments') - comments_content = open(comments_file[0], "r") - for line in comments_content: - if line.split(".", 1)[0] == "-": - print '
' - print ' ' + line.split(".", 1)[1].strip() + ' wrote at ' - elif line.split(".", 1)[0] == "+": - print ' ' + line.split(".", 1)[1].strip() + ':
' - else: - line = line.split(".", 1)[1] - print '   ' + line.strip() + '
' - comments_content.close() - - # Form for adding comments - print '


' - print '
' - print ' ' - print ' ' - print '
' - print '
' - print '
' - - if comments == "True": +# Generate atom feed +if feed_display == "atom": + title = str(entries[0][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '') + date = entries[0][0] + + print 'Content-type: text/html\n' + print '' + print '' + print ' ' + print ' ' + blog_title + '' + print ' ' + print ' ' + blog_title + '' + + blog_title_md5sum = md5.new(blog_title).hexdigest() + blog_title_md5sum_1 = blog_title_md5sum[0:8] + blog_title_md5sum_2 = blog_title_md5sum[8:12] + blog_title_md5sum_3 = blog_title_md5sum[12:16] + blog_title_md5sum_4 = blog_title_md5sum[16:20] + blog_title_md5sum_5 = blog_title_md5sum[20:32] + + print ' urn:uuid:' + blog_title_md5sum_1 + '-' + blog_title_md5sum_2 + '-' + blog_title_md5sum_3 + '-' + blog_title_md5sum_4 + '-' + blog_title_md5sum_5 + '' + print ' ' + str(date[0]) + '-' + str(date[1]) + '-' + str(date[2]) + 'T' + str(date[3]) + ':' + str(date[4]) + ':' + str(date[5]) + 'Z' + print '' + print ' ' + + title_md5sum = md5.new(title).hexdigest() + title_md5sum_1 = title_md5sum[0:8] + title_md5sum_2 = title_md5sum[8:12] + title_md5sum_3 = title_md5sum[12:16] + title_md5sum_4 = title_md5sum[16:20] + title_md5sum_5 = title_md5sum[20:32] + + print ' ' + title + '' + print ' ' + print ' urn:uuid:' + title_md5sum_1 + '-' + title_md5sum_2 + '-' + title_md5sum_3 + '-' + title_md5sum_4 + '-' + title_md5sum_5 + '' + print ' ' + str(date[0]) + '-' + str(date[1]) + '-' + str(date[2]) + 'T' + str(date[3]) + ':' + str(date[4]) + ':' + str(date[5]) + 'Z' + print ' ' + print '' + +# Generate regular page +else: + + print 'Content-type: text/html\n' + print '' + print '' + print ' ' + print ' ' + blog_title + '' + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + + print '
' + print '
' + + if static_display != "": # Show Staticpage + content = open(staticpages_dir + static_display, "r") + print '
' + re.sub('\d+?-', '', static_display) + '
' + print '

' + for line in content: + print ' ' + line.strip() + '
' + print '

' + content.close() + else: # Show regular entry + entry_counter = 0 + for entry in entries: + date = time.strftime("%c", entry[0]) + date_to_compare = time.strftime("%m%Y", entry[0]) # Needed for permalinks + entry = entry[1] + title = entry.replace('entries/', '', 1) + title = title.replace('.' + entries_suffix, '') + + if month_display == date_to_compare or not month_display: + if post_display == title or not post_display: + if allentries_display == "1" or entry_counter < entries_per_page: + content = open(entry, "r") + if permalinks: # Title as permalink... + print ' ' + else: # ... or not + print '
' + title + ' (' + date + ')
' + print '
' + for line in content: + print ' ' + line.strip() + '
' + + # Comments are shown when post_display and comments_file comments_file = glob.glob(entries_dir + title + '.comments') - if not comments_file and not post_display: - print '
' - print ' ' - print '
' - elif comments_file and not post_display: - comments_content = open(comments_file[0], "r") - comments_counter = 0 - for line in comments_content: - if line.split(".", 1)[0] == "-": comments_counter += 1 - print ' ' - comments_content.close() - - print '
' - print '

' - content.close() - entry_counter += 1 - - if not month_display and not post_display and not allentries_display and entry_counter == entries_per_page: # Display pagelist - print '
View all entries...
' - -print '
' -print ' ' -print '' + if post_display: + if comments_file: + print '

' + comments_file = glob.glob(entries_dir + title + '.comments') + comments_content = open(comments_file[0], "r") + for line in comments_content: + if line.split(".", 1)[0] == "-": + print '
' + print ' ' + line.split(".", 1)[1].strip() + ' wrote at ' + elif line.split(".", 1)[0] == "+": + print ' ' + line.split(".", 1)[1].strip() + ':
' + else: + line = line.split(".", 1)[1] + print '   ' + line.strip() + '
' + comments_content.close() + + # Form for adding comments + print '


' + print '
' + print ' ' + print ' ' + print '
' + print '
' + print '
' + + if comments == "True": + comments_file = glob.glob(entries_dir + title + '.comments') + if not comments_file and not post_display: + print '
' + print ' ' + print '
' + elif comments_file and not post_display: + comments_content = open(comments_file[0], "r") + comments_counter = 0 + for line in comments_content: + if line.split(".", 1)[0] == "-": comments_counter += 1 + print ' ' + comments_content.close() + + print '
' + print '

' + content.close() + entry_counter += 1 + + if not month_display and not post_display and not allentries_display and entry_counter == entries_per_page: # Display pagelist + print '
View all entries...
' + + print '
' + print ' ' + print '' # vim: set tw=0 ts=4: -- cgit v1.2.3