Local links again
Pablo Barrera González <barrera-eneoqThHf3GDmu24MmG3/[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <1084525019.922.60.camel@granizo> |
Hello everyone Some days ago I asked about local links in the news of pyblosxom. As I didn't find any way to day I've modified the txt parser and made varrender.py plugin attached. The plugin reads the txt entries and change the $base_url string for its value en the config file. It's not a great think but it does what I need. If it is interesting for pyblosxom I can modify the plugin for reading all the variables in config.py (or a subset). As soon as I found enough free time I will start doing the plugin for multilingual entries. Pablo -- Pablo Barrera González <barrera-eneoqThHf3GDmu24MmG3/[email protected]>
varrender.py
(application/x-python, 1.7 KB)
"""
This parser change the $base_url token in the file by its
value stored in the config file.
Revisions:
0.1 - start (2004-5-11)
"""
__author__ = "Pablo Barrera barrera at gsyc at escet at urjc at es"
__version__ = "0.1"
__url__ = "http://gsyc.escet.urjc.es/~barrera/"
__description__ = "Parse $ variables in the news"
import sys, StringIO
#INIT_KEY = "firstnewfound_initiated"
FILE_EXT = "txt" # replace current txt parser
PREFORMATTER_ID = 'textile'
def verify_installation(request):
# right now, all is ok :-D
return 1
from Pyblosxom import tools
def cb_entryparser(args):
args[FILE_EXT] = readfile
return args
def cb_preformat(args):
if args['parser'] == PREFORMATTER_ID:
return parse(''.join(args['story']))
else:
return ''.join(args['story'])
def readfile(filename, request):
entryData = {}
d = open(filename).read()
# Grab title and body.
title = d.split('\n')[0]
raw_body = d[len(title):]
# locate $ in body
config = request.getConfiguration()
base_url = config.get("base_url", "")
# base_url = "feo"
ind = 0
while 1:
ind_aux = raw_body[ind:].find("$base_url")
if ind_aux == -1:
break
ind = ind + ind_aux
if raw_body[ind:].startswith("$base_url"):
# FIXME This is realy nusty
raw_body = raw_body[:ind] + base_url + raw_body[ind+9:]
else:
ind = ind + 1
entryData = {'title': title,
'body': raw_body}
# Call the postformat callbacks
tools.run_callback('postformat',
{'request': request,
'entry_data': entryData})
return entryData