I added a new feature to my blog: automatic generation of links to followup posts. For example, after writing Put it in the Syntax, I made a couple followup posts that elaborated on the ideas in that post. All of the followups link back to the original, but until now, if I wanted the original to link to the followups I had to put the links in by hand.
With a judicious mixture of server-side includes, a perl script, and crontab, I now have things set up so that every night my website will automatically put a followup link into any old post that I link to from a new post. Here's how it works.
This perl script gets run every night at midnight (via crontab). The script scans through the web page for each of my blog entries, and makes a list of the other entries that it links to. It then generates a new file for each entry, which contains a snippet of html listing all the followups to that post. If there are no followups, then the html snippet is empty. Next, I include the html snippet into the original page, by adding this line to my movabletype entry template:
<!--#include file="<$MTEntryId pad="1"$>.backlinks"-->
And voila, I have automatic generation of followup links. Check out the Put it in the Syntax post to see what it looks like (it's at the bottom of the post, just before the comments). Note that this post isn't actually listed as a followup, because I linked to that post using a different url syntax than I normally do, so it isn't picked up by the perl script.
Posted on December 30, 2003 04:05 PM
More blog articles
Why run the cron job every night? I would think that most nights this will result in the computer spending time doing nothing (with the run time increasing as you add entries). Wouldn't it be better to scan the entry being added, as it's being added (or changed)? Or am I missing something?
Triggering the script based on when an entry is added or modified would require mucking with the MovableType code, which is not something I want to bother with. It's easier just to run the script every night. Besides, it only takes 0.06 seconds to process all 195 posts, so it's not like I'm wasting much of the computer's time.
Posted by: kim at December 30, 2003 06:45 PM