aboutsummaryrefslogtreecommitdiffstats
path: root/blogthon.cgi
blob: 8488393429d4ad4d96d23d66b6e9d0a5c603ad44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/python

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.

# Author: Stefan Ritter <xeno@thehappy.de>
# Description: A simple blogging software

import cgi
import os
import time
import glob
import re
import ConfigParser

configuration = ConfigParser.ConfigParser()
configuration.read('configuration')

blog_title = configuration.get('personal', 'blog_title')
keywords = configuration.get('personal', 'keywords')
entries_dir = configuration.get('personal', 'entries_dir')
entries_suffix = configuration.get('personal', 'entries_suffix')
staticpages_dir = configuration.get('personal', 'staticpages_dir')
style = configuration.get('look', 'style')
entries_per_page = configuration.getint('look', 'entries_per_page')
monthlist = configuration.get('look', 'monthlist')
staticpages = configuration.get('look', 'staticpages')
linklist = configuration.get('look', 'linklist')
permalinks = configuration.get('look', 'permalinks')
newest_first = configuration.get('look', 'newest_first')

action = cgi.FieldStorage()
month_display = action.getvalue('m')
post_display = action.getvalue('p')
static_display = action.getvalue('s')
allentries_display = action.getvalue('a')
if not month_display: month_display = ""
if not post_display: post_display = ""
if not static_display: static_display = ""
if not allentries_display: allentries_display = ""

print 'Content-type: text/html\n'
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'
print '    <head>'
print '        <title>' + blog_title + '</title>'
print '        <meta http-equiv="content-type" content="text/html; charset=utf-8" />'
print '        <meta name="keywords" content="' + keywords + '" />'
print '        <meta name="description" content="' + blog_title + '" />'
print '        <link rel="stylesheet" type="text/css" href="styles/' + style + '" />'
print '    </head>'
print '    <body>'
print '        <div class="title"><a href="?" class="title">' + blog_title + '</a></div>'

entries      = []
entries_list  = glob.glob(entries_dir + '*.' + entries_suffix)

for entry in entries_list:
	timestamp = os.stat(entry)
	timestamp = time.localtime(timestamp[8])
	entry = timestamp, entry
	entries.append(entry)

if newest_first:
	entries.sort(reverse=True)
else:
	entries.sort()

print '        <div class="sidebar">'

if staticpages:
	staticpages = []
	staticpages_list  = glob.glob(staticpages_dir + '*')
	staticpages_list.sort()
	print '            <div class="sidebarentry">'
	print '                <small>pages</small><br />'
	for staticpage in staticpages_list:
		title = re.sub('\w+?\/\d+?-', '', staticpage)
		link = re.sub('\w+?\/', '', staticpage)
		print '                &nbsp;<a href="?s=' + link + '">' + title + '</a>&nbsp;<br />'
	if monthlist: print '                <br />'
	print '            </div>'

if monthlist:
	olddate = ""
	print '            <div class="sidebarentry">'
	print '                <small>months</small><br />'
	for entry in entries:
		date        = time.strftime("%m%Y", entry[0])
		date_display = time.strftime("%h %Y", entry[0])
		if not olddate == date:
			print '                &nbsp;<a href="?m=' + date + '">' + date_display + '</a>&nbsp;<br />'
		olddate = date
	if linklist: print '                <br />'
	print '            </div>'

if linklist:
	content = open("linklist", "r")
	print '            <div class="sidebarentry">'
	print '                <small>links</small><br />'
	for line in content:
		print '                &nbsp;<a href=' + line.split(" ")[0] + '>' + line.split(" ")[-1].strip() + '</a>&nbsp;<br />'
	print '            </div>'
	content.close()

print '        </div>'
print '        <div class="content">'

if static_display != "": # Show Staticpage
	content = open(staticpages_dir + static_display, "r")
	print '            <div class="entrytitle">' + re.sub('\d+?-', '', static_display) + '</div>'
	print '            <div class="entry"><p>'
	for line in content:
		print '                ' + line.strip() + '<br />'
	print '            </p></div>'
	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:
						print '            <div class="entrytitle"><a href="?p=' + title + '" class="entrytitle">' + title + ' <small>(' + date + ')</small></a></div>'
					else:
						print '            <div class="entrytitle">' + title + ' <small>(' + date + ')</small></div>'
					print '            <div class="entry"><p>'
					for line in content:
						print '                ' + line.strip() + '<br />'
					print '            </p></div>'
					print '            <br /><br />'
					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 '            <div class="entry"><a href=?a=1>View all entries...</a></div>'

print '        </div>'
print '    </body>'
print '</html>'

# vim: set tw=0 ts=4: