Comments in the config section added, some encoding bugs fixed, now using mtime for the post dates

master
Stefan Krulj 15 years ago
parent 4e63b6c101
commit 6e845d2506
  1. 28
      pylog.py
  2. 25
      pylog_action_impl.py
  3. 25
      pylog_config.py
  4. 66
      style.css
  5. 0
      tex.cgi

@ -72,10 +72,10 @@ def disp_list(path):
for f in os.listdir(path): for f in os.listdir(path):
f = os.path.normpath(os.path.join(path,f)) f = os.path.normpath(os.path.join(path,f))
if not os.path.isdir(f): if not os.path.isdir(f):
if not os.path.getctime(f) in files: if not os.path.getmtime(f) in files:
files[os.path.getctime(f)]=[f] files[os.path.getmtime(f)]=[f]
else: else:
files[os.path.getctime(f)].append(f) files[os.path.getmtime(f)].append(f)
keys = files.keys() keys = files.keys()
keys.sort() keys.sort()
keys.reverse() keys.reverse()
@ -134,10 +134,10 @@ def get_newest(n):
allfiles=get_all() allfiles=get_all()
files = {} files = {}
for f in allfiles: for f in allfiles:
if not os.path.getctime(f) in files: if not os.path.getmtime(f) in files:
files[os.path.getctime(f)]=[f] files[os.path.getmtime(f)]=[f]
else: else:
files[os.path.getctime(f)].append(f) files[os.path.getmtime(f)].append(f)
keys = files.keys() keys = files.keys()
keys.sort() keys.sort()
keys.reverse() keys.reverse()
@ -146,7 +146,7 @@ def get_newest(n):
def get_valid_path(path): def get_valid_path(path):
if '..' in path or os.path.normpath(path)=='.': if '..' in path or os.path.normpath(path)=='.':
return cfg.contentdir return cfg.contentdir
valid_chars='.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_0123456789' valid_chars='. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/_0123456789'
for c in path: for c in path:
if not c in valid_chars: if not c in valid_chars:
return cfg.contentdir return cfg.contentdir
@ -170,8 +170,8 @@ else:
<channel> <channel>
<atom:link href="'''+cfg.topurl+script+'?rss=1'+'" rel="self" type="application/rss+xml" />' <atom:link href="'''+cfg.topurl+script+'?rss=1'+'" rel="self" type="application/rss+xml" />'
print " <title>"+cfg.blogtitle+"</title>" print (" <title>"+cfg.blogtitle+"</title>").encode(cfg.encoding)
print " <description>"+cfg.subtitle+"</description>" print (" <description>"+cfg.subtitle+"</description>").encode(cfg.encoding)
print " <link>"+cfg.topurl+script+"</link>" print " <link>"+cfg.topurl+script+"</link>"
print " <generator>Pylog "+__version+"</generator>" print " <generator>Pylog "+__version+"</generator>"
if len(keys)>0: if len(keys)>0:
@ -221,13 +221,13 @@ print '<!DOCTYPE html>'
print '<html>' print '<html>'
print '<head>' print '<head>'
print '<meta charset="UTF-8">' print '<meta charset="UTF-8">'
print '<title>'+cfg.title+'</title>' print ('<title>'+cfg.title+'</title>').encode(cfg.encoding)
print '<link rel="alternate" type="application/rss+xml" title="RSS" href="'+cfg.topurl+script+'"?rss=1 />' print '<link rel="alternate" type="application/rss+xml" title="RSS" href="'+cfg.topurl+script+'"?rss=1 />'
print cfg.header print cfg.header.encode(cfg.encoding)
print '</head>' print '</head>'
print '<body>' print '<body>'
print '<h1 id="blogtitle"><a href="'+script+'">'+cfg.blogtitle+'</a></h1>' print ('<h1 id="blogtitle"><a href="'+script+'">'+cfg.blogtitle+'</a></h1>').encode(cfg.encoding)
print '<h2 id="subtitle">'+cfg.subtitle+'</h2>' print ('<h2 id="subtitle">'+cfg.subtitle+'</h2>').encode(cfg.encoding)
print '<div id="menu">' print '<div id="menu">'
process_dirs(cfg.contentdir,path) process_dirs(cfg.contentdir,path)
print '</div>' print '</div>'
@ -249,7 +249,7 @@ try:
sys.stdout.write('<h1><span class="entryheader">') sys.stdout.write('<h1><span class="entryheader">')
print name+'</span> - <span class="entrydate">', print name+'</span> - <span class="entrydate">',
print datetime.fromtimestamp( \ print datetime.fromtimestamp( \
int(os.path.getctime(validdisp)) \ int(os.path.getmtime(validdisp)) \
).strftime(cfg.datefmt), ).strftime(cfg.datefmt),
print '</span></h1>' print '</span></h1>'

@ -1,5 +1,5 @@
import os, os.path, stat, sys import os, os.path, stat, sys
import urllib, hashlib import urllib, hashlib, codecs
from datetime import datetime from datetime import datetime
import pylog_config as cfg import pylog_config as cfg
import subprocess,tempfile import subprocess,tempfile
@ -37,8 +37,9 @@ def file_link(name,f,depth,hidden):
def disp_txt(path): def disp_txt(path):
print '<div class="entrytext">' print '<div class="entrytext">'
f = open(path) f = codecs.open(path, mode="r", encoding=cfg.encoding)
print markdown.markdown(f.read(),extensions=['math']) txt=f.read()
print markdown.markdown(txt,extensions=['math']).encode(cfg.encoding)
f.close() f.close()
print '</div>' print '</div>'
@ -80,7 +81,7 @@ def get_source_html(path):
s.st_mode & stat.S_IRWXG == 0 and \ s.st_mode & stat.S_IRWXG == 0 and \
s.st_mode & stat.S_IRWXO == 0 and \ s.st_mode & stat.S_IRWXO == 0 and \
os.path.isdir(tmpdir): os.path.isdir(tmpdir):
f=open(path,'r') f=codecs.open(path, mode='r', encoding=cfg.encoding)
tmpfile=os.path.join(tmpdir,hashlib.sha256(f.read()).hexdigest()) tmpfile=os.path.join(tmpdir,hashlib.sha256(f.read()).hexdigest())
f.close() f.close()
cache=True cache=True
@ -107,7 +108,7 @@ def get_source_html(path):
p.stderr.close() p.stderr.close()
p.wait() #wait for child to terminate p.wait() #wait for child to terminate
f=open(tmpfile,"r") f=codecs.open(tmpfile, mode="r", encoding=cfg.encoding)
bp=BodyParser() bp=BodyParser()
bp.feed(f.read()) bp.feed(f.read())
src = bp.src src = bp.src
@ -119,14 +120,14 @@ def get_source_html(path):
def disp_source(path): def disp_source(path):
print '<div class="sourcecode">' print '<div class="sourcecode">'
print get_source_html(path) print get_source_html(path).encode(cfg.encoding)
#print source #print source
print '</div>' print '</div>'
def disp(path): def disp(path):
print '<div class="entrytext">' print '<div class="entrytext">'
f = open(path) f = codecs.open(path, mode="r", encoding=cfg.encoding)(path)
print f.read() print f.read().encode(cfg.encoding)
f.close() f.close()
print '</div>' print '</div>'
@ -149,18 +150,18 @@ def get_n_words(fi,n):
return (txt,False) return (txt,False)
def prev(path): def prev(path):
fi = open(path) fi = codecs.open(path, mode="r", encoding=cfg.encoding)
txt=get_n_words(fi,40) txt=get_n_words(fi,40)
print '<div class="preview">'+txt[0] print '<div class="preview">'+txt[0].encode(cfg.encoding)
if txt[1]: if txt[1]:
print '<i>&nbsp;...</i>' print '<i>&nbsp;...</i>'
print '</div>' print '</div>'
fi.close() fi.close()
def prev_txt(path): def prev_txt(path):
fi = open(path) fi = codecs.open(path, mode="r", encoding=cfg.encoding)
txt=get_n_words(fi,40) txt=get_n_words(fi,40)
print '<div class="preview">'+markdown.markdown(txt[0],extensions=['math']) print '<div class="preview">'+markdown.markdown(txt[0],extensions=['math']).encode(cfg.encoding)
if txt[1]: if txt[1]:
print '<i>&nbsp;...</i>' print '<i>&nbsp;...</i>'
print '</div>' print '</div>'

@ -1,14 +1,21 @@
title = 'Title of destruction' title = 'PyLog' # Title displayed on the browser window
blogtitle= 'Le Blog' blogtitle= 'Plog' # The blog's title
subtitle='Some subtitle... and cats!' subtitle=u'produced py Powertomato \xb0\u0DF4\xb0' # The text to be displayed under the blog title
header=""" header="""
<link rel="stylesheet" type="text/css" href="style.css" /> <link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="source.css" /> <link rel="stylesheet" type="text/css" href="source.css" />
""" """ # This header will be printed in the <head> section of the html file
datefmt='%Y-%m-%d'
contentdir="cnt"
numofposts=5 #number of previews on the base site
numfeed=5 #number of previews in the feed
topurl="http://n0g.at/~powertomato/pylog/" datefmt='%Y-%m-%d' # format of the date which is displayed next to the entry
# See pythons manual reference for time.strptime for details
contentdir="cnt" # directory where the content is located
numofposts=5 # number of previews on the base site
numfeed=5 # number of previews in the feed
topurl="http://n0g.at/~powertomato/pylog/" # The URL which specifies the scripts location
# if someone knows how to obtain it using CGI
# please let me know
encoding="utf-8" # The content files should be encoded using this
# format. See manual reference for codecs.open for
# details

@ -2,15 +2,38 @@
.hidden { .hidden {
display: none display: none
} }
li {
list-style-type:disc;
}
a { a {
color:#aa6735; color:#aa6735;
text-decoration:underline; text-decoration:underline;
font-weight:bold; font-weight:bold;
} }
a:hover{ a:hover {
text-decoration:none; text-decoration:none;
} }
code {
font-size:10pt;
font-family:monospace;
background-color:#dddddd;
border:1px solid #aaaaaa;
padding-left:4px;
padding-right:4px;
}
pre code{
display:block;
margin-left: 20px;
font-size:10pt;
font-family:monospace;
background-color:#dddddd;
border:1px solid #aaaaaa;
padding-left:4px;
padding-right:4px;
}
/* header */ /* header */
h1#blogtitle, h1#blogtitle a{ h1#blogtitle, h1#blogtitle a{
text-decoration:none; text-decoration:none;
@ -22,6 +45,10 @@ h1#blogtitle, h1#blogtitle a{
background-color:#dddddd; background-color:#dddddd;
height:35px; height:35px;
background-image:url(_img/tbg.png); background-image:url(_img/tbg.png);
border-width:0px;
}
h2#subtitle:before {
content:none;
} }
h2#subtitle { h2#subtitle {
font-size:10pt; font-size:10pt;
@ -41,7 +68,7 @@ h2#subtitle {
width:15%; width:15%;
margin-left:1%; margin-left:1%;
} }
#menu ul,li{ #menu ul, #menu li{
margin:0; margin:0;
padding:0; padding:0;
list-style-type:none; list-style-type:none;
@ -50,7 +77,6 @@ h2#subtitle {
padding-left:15px; padding-left:15px;
border-collapse:collapse; border-collapse:collapse;
} }
#menu ul, #menu ul ul ul{ #menu ul, #menu ul ul ul{
} }
@ -102,21 +128,49 @@ body {
} }
h1 { h1 {
font-size:14pt; font-size:14pt;
margin:15px 0 0 0; padding:10px 0 0 0;
font-weight:bold; font-weight:bold;
color:#5598ca; color:#5598ca;
border-bottom:1px solid #5598ca;
counter-reset: kap;
}
h1 a {
text-decoration:none;
}
h2:before {
content: counter(kap) ' ';
} }
h2 { h2 {
font-size:12pt; font-size:12pt;
margin:20px 0 0 0; padding:10px 0 0 10px;
font-weight:bold; font-weight:bold;
color:#5598ca; color:#5598ca;
counter-increment: kap;
counter-reset: subkap;
}
h3:before {
content: counter(kap) '.' counter(subkap) ' ';
} }
h3 { h3 {
font-size:10pt; font-size:10pt;
margin:25px 0 0 0; padding:10px 0 0 20px;
font-weight:bold; font-weight:bold;
color:#5598ca; color:#5598ca;
counter-increment: subkap;
counter-reset: subsubkap;
}
h4:before {
content: counter(kap) '.' counter(subkap) '.' counter(subsubkap) ' ';
}
h4 {
font-size:9pt;
padding:10px 0 0 30px;
font-weight:bold;
color:#5598ca;
counter-increment: subsubkap;
} }
.entryheader { .entryheader {
color:#5598ca; color:#5598ca;

Loading…
Cancel
Save