An HTML Entry Parser

Joseph Reagle <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.user
Organization NYU
Message-ID <[email protected]>
Wari, based on what you sent me, these few tweaks do the trick for me in 
terms of providing the entryData. However, the effect on my main blog page 
is rather disastrous. I suspect that the parser is finding the 
{comment,foot,head.html} files and trying to render them as blog entries? 
(I always thought it was odd that those "config" files existed in the 
content directory). Or are the excepted somewhere?


FILE_EXT = 'html'
"""
Files with a .html extension will be an entry.
"""
__version__ = '$Id:$'
__author__ = 'Joseph Reagle [email protected]'

def cb_entryparser(args):
    args[FILE_EXT] = readfile
    return args

def readfile(filename, request):
    
    from Pyblosxom import tools
    
    entryData = {}
    html = file(filename).read()
    #title = "TEST" # lookForTitle(d)
    title = html[html.find('<h1>') + 4:html.find('</h1>')]
    # You can also look for other metadata (META tags?)
    body = html[html.find('<body>') + 6:html.find('</body>')]
    # Something like the above can be extracted with sgmlparser as well.
    entryData = {'title': title,
                'body': body}
    # Call the postformat callbacks
    tools.run_callback('postformat',
            {'request': request,
            'entry_data': entryData})
    
    return entryData



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.