Shows newest posts now if in base dir, blog title now links to base dir

master
Stefan Krulj 15 years ago
parent 5a20003666
commit c0de1e77a8
  1. 2
      mdx_math.py
  2. 95
      pylog.py
  3. 1
      pylog_action_impl.py
  4. 2
      pylog_config.py
  5. 3
      style.css

@ -8,8 +8,8 @@ class MathPattern(Pattern):
def __init__(self,md):
Pattern.__init__(self,"!\[math\]\((.*?)\)\[math\]",md)
def handleMatch(self, m):
texcode=m.group(2)
texcode=m.group(2)
el = markdown.util.etree.Element('img')
el.attrib["src"]="tex.cgi?"+self.unescape(texcode)

@ -14,12 +14,12 @@ import pylog_config as cfg
print 'Content-type: text/html\n\n'
def header():
script = sys.argv[0][sys.argv[0].rindex('/')+1:]
print '<head>'
print '<title>'+cfg.title+'</title>'
print '<h1 id="blogtitle">'+cfg.blogtitle+'</h1>'
print '<h1 id="blogtitle"><a href="'+script+'">'+cfg.blogtitle+'</a></h1>'
print '<h2 id="subtitle">'+cfg.subtitle+'</h2>'
print cfg.header
print '</head>'
@ -73,33 +73,85 @@ def process_dirs(path='.',disppath='.',depth=0,hidden=False):
dir_end(disppath,hidden)
def disp_list(path):
script = sys.argv[0][sys.argv[0].rindex('/')+1:]
if path==cfg.contentdir:
files,keys=get_newest(cfg.numofposts)
disp_file_dict(files,keys)
return
files = {}
for f in os.listdir(path):
f = os.path.normpath(os.path.join(path,f))
if not os.path.isdir(f):
files[os.path.getctime(f)]=f
if not os.path.getctime(f) in files:
files[os.path.getctime(f)]=[f]
else:
files[os.path.getctime(f)].append(f)
keys = files.keys()
keys.sort()
keys.reverse()
disp_file_dict(files,keys)
def disp_file_dict(d,keys):
script = sys.argv[0][sys.argv[0].rindex('/')+1:]
for k in keys:
f=files[k]
if '.' in os.path.basename(f):
typ = f[f.rindex('.')+1:]
name = os.path.basename(f)[:-(len(typ)+1)]
for f in d[k]:
if '.' in os.path.basename(f):
typ = f[f.rindex('.')+1:]
name = os.path.basename(f)[:-(len(typ)+1)]
else:
typ = ''
name = os.path.basename(f)
if typ in prev_actions and not os.path.isdir(f):
sys.stdout.write('<h1><a class="entryheader" href="'+script+'?')
sys.stdout.write(urllib.urlencode({'path': os.path.normpath(os.path.dirname(f)), \
'disp':os.path.normpath(f)})+'">')
print name+'</a> - <span class="entrydate">',
print datetime.fromtimestamp(int(k)).strftime(cfg.datefmt),
print '</span></h1>'
prev_actions[typ](f)
def get_all(path=cfg.contentdir):
dicts = []
files = []
for f in os.listdir(path):
f = os.path.normpath(os.path.join(path,f))
if not os.path.isdir(f):
if '.' in os.path.basename(f):
typ = f[f.rindex('.')+1:]
name = os.path.basename(f)[:-(len(typ)+1)]
else:
typ = ''
name = os.path.basename(f)
if typ in prev_actions:
files.append(f)
else:
typ = ''
name = os.path.basename(f)
if typ in prev_actions and not os.path.isdir(f):
sys.stdout.write('<h1><a class="entryheader" href="'+script+'?')
sys.stdout.write(urllib.urlencode({'path': os.path.normpath(os.path.dirname(f)), \
'disp':os.path.normpath(f)})+'">')
print name+'</a> - <span class="entrydate">',
print datetime.fromtimestamp(int(k)).strftime(cfg.datefmt),
print '</span></h1>'
prev_actions[typ](f)
if '_' in os.path.basename(f):
typ = f[f.rindex('_')+1:]
name = os.path.basename(f)[:-(len(typ)+1)]
else:
typ = ''
name = os.path.basename(f)
if typ in dir_actions:
dicts.append(f)
for d in dicts:
files+=get_all(d)
return files
def get_newest(n):
allfiles=get_all()
files = {}
for f in allfiles:
if not os.path.getctime(f) in files:
files[os.path.getctime(f)]=[f]
else:
files[os.path.getctime(f)].append(f)
keys = files.keys()
keys.sort()
keys.reverse()
return files,keys[0:n]
def get_valid_path(path):
if '..' in path or os.path.normpath(path)=='.':
@ -110,13 +162,16 @@ def get_valid_path(path):
return cfg.contentdir
return os.path.normpath(path)
print 'Content-type: text/html\n\n'
path = cfg.contentdir
if 'path' in form:
path=form['path'].value
path=get_valid_path(path)
print '<html>'
header()
print '<body>'

@ -64,7 +64,6 @@ class BodyParser(HTMLParser):
if self.body:
self.src += '&'+ref+';'
def get_source_html(path):
tmpdir = os.path.join(tempfile.gettempdir(),"pylog")
cache=False

@ -8,3 +8,5 @@ header="""
"""
datefmt='%Y-%m-%d'
contentdir="cnt"
numofposts=5 #number of previews on the base site
numfeed=5 #number of previews in the feed

@ -12,7 +12,8 @@ a:hover{
}
/* header */
h1#blogtitle {
h1#blogtitle, h1#blogtitle a{
text-decoration:none;
font-size:18pt;
font-weight:bold;
padding:20px 0 0 15px;

Loading…
Cancel
Save