April 2003 archive

Playing with Weblogs

I’ve completed a massive overhaul of my growlmurrdurr weblog system. It is now exactly a thousand times more nicely written, expandable, and just generally clean and happy. No longer do I have to cringe every time I want to make a change to it.

Now that it is more generic and clean and happy, after a bit of testing I’ll be releasing it upon the world on my software page. I’ll even write some documentation and stuff, explaining how to set it up. It’s nice and robust now, such that modifications to the source files shouldn’t be required just to get it up and running. Give or take a bit.

I’ve been pondering the best way to create some kind of configuration system for it. Some kind of more robust administration than it currently has, so that it could be expanded to do more in the future. Multiple author support, for example, will require some way for the administrator to create multiple author ‘accounts’ and so on. Anyways, I’m happy with the new setup. It’s up-to-date in the Subversion repository, if you’re interested in taking a look-see.

Google Search Term Highlighting

Earlier today I was searching around Google for some technical information, and was given Expert Exchange as a link. Experts Exchange has this nifty little feature, implemented as an Apache module, whereby the HTTP referer is examined for search engine footprints. When it is found that you were linked by a search engine, this Apache module named mod_suru will highlight those search terms inside the resultant web page.

“Cool,” I thought. So I went to look at mod_suru and discovered that it is only available at a relatively high cost. Certainly not a cost that I’m willing to pay for my own personal website.

So I took another path. I re-implemented the same idea as mod_suru through primarily JavaScript. My stomphighlight.js file defines a function, highlightWord, which does the magic of actually highlighting the text. The magic of determining which words to highlight is highly dependant upon the setup that the web site has. In the case of stompstompstomp.com, every footer on every page is served by a Python function. I added the following code to my footer:


import os, re, cgi

# Highlight google-ed for words!
if os.environ.has_key("HTTP_REFERER"):
    words = None

    m = re.search("google.[a-z.]+/search\\?(.*)", os.environ['HTTP_REFERER'])
    if m:
        googleQuery = cgi.parse_qs(m.group(1))
        words = ' '.join(googleQuery['q']).split(' ')
        words = filter(lambda x: x.find(":") == -1, words) # remove words like 'site:blahblah.com'

    if words != None:
        print "<!-- Begin magical search term highlighting. -->"
        print """<script language="JavaScript" type="text/javascript" src="/stomphighlight.js"></script>"""
        colors = ("#00eeee", "#eeee00", "#ee00ee", "#ee0000", "#00ee00", "#0000ee")
        print """<script language="JavaScript" type="text/javascript"><!--"""
        for i in range(len(words)):
            try:
                print "highlightWord(%r, %r, document.documentElement);" % (words[i], colors[i])
            except IndexError:
                pass
        print """//--></script>"""
        print "<!-- End magical search term highlighting. -->"

Hopefully, it should be pretty clear how you could take this and use the same idea on your own web site, or modify my code to support more than just Google. Yay!