metanohi/macros/macros.py

42 lines
1.5 KiB
Python
Raw Normal View History

# macros
2011-07-26 03:04:17 +02:00
import sys
import os.path
# Ugly hack for local installations
htmlgen = sys.modules['mege.htmlgen']
htmlfunc = sys.modules['mege.htmlfunc']
import mege.git as git
import mege.misc as misc
def list_pages(pathdir=None):
pathdir = misc.macrog('pathdir', pathdir)
2011-07-26 03:04:17 +02:00
dl = htmlfunc.DefList()
2011-08-01 22:39:41 +02:00
fs = [(p if os.path.isfile(p) else os.path.join(
p, 'index.org'), f, f[:-4] if os.path.isfile(p) else f + '/') for p, f in filter(
lambda pf: (os.path.isfile(pf[0]) and pf[0].endswith('.org') and
pf[1] != 'index.org') or (
os.path.isdir(pf[0]) and os.path.isfile(os.path.join(pf[0], 'index.org'))),
((os.path.join(pathdir, f), f) for f in os.listdir(pathdir)))]
2011-07-26 03:04:17 +02:00
fs.sort(key=lambda pf: git.rr.get_last_modified_date(pf[0])[0] or
misc.utcwhenmodified(pf[0]))
2011-08-01 22:39:41 +02:00
for p, f, l in fs[::-1]:
2011-07-26 03:04:17 +02:00
a = htmlgen.org_to_abstract(p, isfile=True, only_metadata=True)
2011-08-01 22:39:41 +02:00
dl.add_item(htmlfunc.link(l, a.title), a.summary if a.summary
2011-07-27 02:44:23 +02:00
else None) #'No summary.')
2011-07-26 03:04:17 +02:00
return dl.generate_html()
def titlelink(path, pathdir=None):
2011-08-13 18:09:32 +02:00
if not path.startswith('/'):
pathdir = misc.macrog('pathdir', pathdir)
orgpath = misc.get_org_path(os.path.join(pathdir, path))
else:
orgpath = misc.get_org_path(os.path.join('site', path[1:]))
2011-07-26 03:04:17 +02:00
if orgpath:
a = htmlgen.org_to_abstract(orgpath, isfile=True, only_metadata=True)
title = a.title
else:
title = path
return htmlfunc.link(path, title).generate_html()