"""
usertitle.py pyblosxom plugin
Sets the page title appropriately if there is only one entry in view.
usertitle.py adds a new variable which will contain the standard
'blog_title_with_path' page title, unless there is only one entry in
view. If there is only one entry in view, the page title is augmented
with the story title aswell. This makes search engine results and
browsers happier, as they can recognize what your page is about by
the title!
This is based on page_title.py by Jordan Sissel
The new variable you want to use is:
$blog_title_or_entry_title
ie:
$user_title
CONFIGURATION
In config.py, add:
py['usertitle_variable'] = "blog_title_with_path"
or whatever $variable you currently use for the page title.
"""
__author__ = 'Akkana Peck '
__version__ = '20100402'
__url__ = 'http://shallowsky.com/software/pyblosxom/'
def cb_prepare(args):
request = args["request"]
config = request.getConfiguration()
data = request.getData()
if data.has_key("entry_list"):
# Is it a single entry page? If so, use the page title.
if len(data["entry_list"]) == 1:
title = "%s (%s)" % (data["entry_list"][0].getMetadata('title'), config["blog_title"])
data["user_title"] = title
else :
# Else it could be the top level, a category page or a tags page.
# usertitle comes from blog_title_with_path and is something like
# 'Shallow Thoughts : /linux/kernel/index.html'
# or 'Shallow Thoughts : tags /linux/index'
# or 'Shallow Thoughts : /index.html'
paths = data[config["usertitle_variable"]].split('/')
# In all cases, get rid of the final index entry:
if len(paths) > 1 :
paths = paths[:-1]
# If that's all, we're probably on the top level:
if len(paths) <= 1 :
data["user_title"] = config["blog_title"]
# Otherwise, combine the first and last pieces:
else :
data["user_title"] = "%s : %s" % (paths[0], paths[-1])