Tuesday, June 14, 2011

Beware Old Posts

I noticed that many of my older posts are woefully out of date. I added a little JavaScript snippet to warn you about that. There's probably a more elegant way to do this, but it'll work for now.
var message = " <span style='font-size: 20px; font-weight: bold; color: red;'>STOP! This is an old post. Are you sure it's still relevant?</span>";
var currentDate = new Date();
var thisYear = currentDate.getFullYear();
var lastYear = currentDate.getFullYear() - 1;

function stringDoesNotContainYear(myString, myYear) {
return myString.indexOf(myYear) == -1;
}

$(document).ready(function() {
$(".date-header").each(function(){
current = $(this).text();
if(stringDoesNotContainYear(current, thisYear) && stringDoesNotContainYear(current, lastYear)) {
$(this).append(message);
}
});
});

No comments: