Category title plugin
Ross Burton <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <1095408656.4478.6.camel@localhost> |
Hi, To avoid hoarding some of the possibly-useful small plugins I've written, attached is section_title.py and section_body.py. Sadly I'm still running pyblosxom 0.8 so these may not work with 1.0... upgrading continually falling to the bottom of my to do list. :( section_title.py allows you to create a '.title' file in each category directory, the contents of which are used as the blog title instead of the real name of the directory. For example, my blosxom/sound-juicer category would normally set "sound- juicer" as the HTML <title>, but blosxom/sound-juicer/.title contains "Sound Juicer" so the HTML <title> is set to that instead. section_body.py lets you have an entry called body.txt which is moved to be the first entry for specified flavours. If anyone tries these, discovers they don't work with Pyblosxom 1.0 and fixes them, please mail me. :) Ross -- Ross Burton mail: [email protected] jabber: [email protected] www: http://www.burtonini.com./ PGP Fingerprint: 1A21 F5B0 D8D0 CFE3 81D4 E25A 2D09 E447 D0B4 33DF
section_body.py
(application/x-python, 2.1 KB)
""" This plugin injects an entry to the beginning of the entry_list (unless the entry_list has no entries in it) that lists some vital information. It requires you to set "section_body_allowed_flavour_list" to the list of flavours that you want this to inject an entry for. ex: py["section_body_flavour_list"] = ["html", "xhtml"] """ __author__ = "Ross Burton <[email protected]>" __version__ = "0.2" from Pyblosxom.entries.fileentry import FileEntry def cb_prepare(args): """ This method gets called in the prepareChain. It gets passed the Request object as the first member of the args tuple. """ request = args["request"] data = request.getData() config = request.getConfiguration() pyhttp = request.getHttp() # if we have no entries, we want to keep it that way so the 404 # message pops up. entry_list = data.get("entry_list", []) if len(entry_list) <= 0: return # Remove any existing body entries for e in ([e for e in entry_list if e['fn']=='body']): entry_list.remove(e) # we only want to inject an entry for certain flavours. for instance # we don't want to do this for rss feeds since it'll make the # feedreaders unhappy. flavour = data.get("flavour", "html") allowed_flavour_list = config.get("section_body_allowed_flavour_list", []) if flavour not in allowed_flavour_list: return try: # ok--if we get here, then we definitely want to insert an entry. entry = FileEntry(config, config["datadir"] + '/' + data['pi_bl'] + "/body.txt", data['root_datadir']) # now we insert this new entry into the beginning of the entry list. entry_list.insert(0, entry) except Exception, e: return # this is interesting since we're actually changing the configuration # data. since the injected entry isn't a "real entry", we want to # make sure that it doesn't bump out a real entry from viewing. maxcount = config.get("num_entries", None) if maxcount: maxcount += 1 config["num_entries"] = maxcount
section_title.py
(application/x-python, 989 B)
""" Allow sections to change the title of the page. If the directory contains a file called '.title', the first line of this file is used as the page's title. Copyright (C) 2004 Ross Burton <[email protected]> """ __author__ = "Ross Burton <[email protected]>" __version__ = "0.1" def cb_prepare(args): """ This method gets called in the prepareChain. It gets passed the Request object as the first member of the args tuple. """ request = args["request"] data = request.getData() config = request.getConfiguration() # If we have no entries, we want to keep it that way so the 404 message # title is correct. entry_list = data.get("entry_list", []) if len(entry_list) <= 0: return try: f = open(config["datadir"] + '/' + data['pi_bl'] + "/.title") title = f.readline() config['blog_title'] = title.strip() except Exception, e: return