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. 67
      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): def __init__(self,md):
Pattern.__init__(self,"!\[math\]\((.*?)\)\[math\]",md) Pattern.__init__(self,"!\[math\]\((.*?)\)\[math\]",md)
def handleMatch(self, m): def handleMatch(self, m):
texcode=m.group(2)
texcode=m.group(2)
el = markdown.util.etree.Element('img') el = markdown.util.etree.Element('img')
el.attrib["src"]="tex.cgi?"+self.unescape(texcode) 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(): def header():
script = sys.argv[0][sys.argv[0].rindex('/')+1:]
print '<head>' print '<head>'
print '<title>'+cfg.title+'</title>' 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 '<h2 id="subtitle">'+cfg.subtitle+'</h2>'
print cfg.header print cfg.header
print '</head>' print '</head>'
@ -73,18 +73,29 @@ def process_dirs(path='.',disppath='.',depth=0,hidden=False):
dir_end(disppath,hidden) dir_end(disppath,hidden)
def disp_list(path): 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 = {} files = {}
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):
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 = files.keys()
keys.sort() keys.sort()
keys.reverse() 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: for k in keys:
f=files[k] for f in d[k]:
if '.' in os.path.basename(f): if '.' in os.path.basename(f):
typ = f[f.rindex('.')+1:] typ = f[f.rindex('.')+1:]
name = os.path.basename(f)[:-(len(typ)+1)] name = os.path.basename(f)[:-(len(typ)+1)]
@ -101,6 +112,47 @@ def disp_list(path):
prev_actions[typ](f) 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:
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): 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
@ -110,13 +162,16 @@ def get_valid_path(path):
return cfg.contentdir return cfg.contentdir
return os.path.normpath(path) return os.path.normpath(path)
print 'Content-type: text/html\n\n'
path = cfg.contentdir path = cfg.contentdir
if 'path' in form: if 'path' in form:
path=form['path'].value path=form['path'].value
path=get_valid_path(path) path=get_valid_path(path)
print '<html>' print '<html>'
header() header()
print '<body>' print '<body>'

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

@ -8,3 +8,5 @@ header="""
""" """
datefmt='%Y-%m-%d' datefmt='%Y-%m-%d'
contentdir="cnt" 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 */ /* header */
h1#blogtitle { h1#blogtitle, h1#blogtitle a{
text-decoration:none;
font-size:18pt; font-size:18pt;
font-weight:bold; font-weight:bold;
padding:20px 0 0 15px; padding:20px 0 0 15px;

Loading…
Cancel
Save