Adding an "On this day" header to your blog.

I've always thought it was cool to be able to find out what happened in history on a particular day. This used to be limited to encyclopedias and birthday cards, but in the "information age" this type of information is available from a lot of places fairly easily. The more I have been blogging, the more I wanted to incorporate this kind of information in my personal blog.

Since my personal blog is a blogger.com hosted blog, I started searching the blogger.com help and ran across some information on how to do this, but the link was dead. Fortunately, I was able to find a that had it implemented (which I believe is the original) and was able to view the javascript code.

After looking at the code for a few minutes, I decided that it would get the job done but that it could be better. I rewrote it, added some stylesheet definitions, and implemented it on my blog. I posted an entry on how to use it, but thought I would write a more in-depth article.

The idea behind this function is very simple. You pass a properly formatted date string as the only argument to the function, which returns a fully formatted HTML string that can be embedded in your blog. I had the following goals in mind when I wrote this function:

  • Simplicity
  • Extensibility
  • Performance

In order to use this function, you must have the ability to customize the look of your blog. For those of you who are hosting your own blogs this isn't a problem. Those blogs that are on public blog hosting sites need the ability to customize the template you are using. Blogger.com allows you to do this, but GeeksWithBlogs does not.

The first step is to add the Javascript function to your template. The best place to do this is in the <HEAD> section.

Now that you have added the Javascript, you need to include the relevant CSS definitions. This can be done by adding them to an included stylesheet or by including them in an in-line stylesheet. You are free to change them to fit the look of your own blog, but I don't recommend changing the class name. The definitions that I used are:

.on-this-day-header { border-bottom:2px dotted #999; }

.on-this-day { margin:1.5em 0.5em; font:78%/1.4em "Trebuchet MS",Trebuchet,Arial,Verdana,Sans-serif; text-transform:uppercase; letter-spacing:.2em; color:#999; }

Now you are ready to incorporate the function call. This really can be done anywhere in your blog, but it makes the most sense to include it with the date header. This will be different for every blog, but for a Blogger.com hosted blog, you are looking for the section enclosed by the <BLOGDATEHEADER> element. It usually looks like this:

<$BlogDateHeaderDate$>

You need to change the <BLOGDATEHEADER> content so it looks like this:

<$BlogDateHeaderDate$>

If you want to add a new site to the function, there are 4 simple steps to follow. For example, to add the BrainyHistory site to the function:

  1. Modify the returnString variable to include the placeholder text for your new site. Remember, the order of the entries listed here will be the same order they are displayed, so make sure you put it in the correct spot.

var returnString = "On this day: #Wikipedia# ‡ #HistoryChannel# ‡ #NYTimes# ‡ #BBC# ‡ #IMDB# ‡ #Reference# ‡ #Britannica# ‡ #BrainyHistory# ‡ #DailyBleed# ‡ #OnThisDay#";

  1. Add the following template variable:

var BrainyHistory = "<a target=\"_blank\" href=\"http://www.brainyhistory.com/days/#month#\_#day#.html\\">Brainy History";

  1. Add the following fixup code:

var dailyBleed = DailyBleed.replace(/#month#/, (month < 10? "0" + month: month)).replace(/#day#/, (day < 10? "0" + day: day));

In this case, the URL requires some additional logic to fixup the template parameters. This logic should be encapsulated in the template fixup code only.

  1. Modify the return statement to add the new URL

return returnString.replace(/#Wikipedia#/, wikipedia) .replace(/#HistoryChannel#/, historyChannel) .replace(/#NYTimes#/, nyTimes) .replace(/#BBC#/, bbc) .replace(/#IMDB#/, imdb) .replace(/#Reference#/, reference) .replace(/#Britannica#/, britannica) .replace(/#BrainyHistory#/, brainyHistory) .replace(/#DailyBleed#/, dailyBleed) .replace(/#OnThisDay#/, onThisDay) ;

This article is part of the GWB Archives. Original Author: Scott Dorman

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.