Artificially intelligent IA
February 26, 2003 04:06 PMFor a while now, I’ve had one small desire with my weblog setup. I want the information architecture of the archives to be a little more coherent. I’m a firm believer that a page’s URL should be descriptive of the content.
Unfortunatley, the default Movable Type install creates archive files that looks something like this:
www.myblog.com/archives/0000123.html/
Trying to parse that URL tells me absolutlely nothing about the content it points to. A much more coherent IA would be something like:
www.myblog.com/2003/02/my_entry_title.html/
A quick glance gives you all kinds of information, including when it was published and what kind of content you can expect.
Fortunately, the brains behind Movable Type saw it fit to build the mechanism to make this happen. You just gotta finesse it a bit. Here’s how.
Prepping your old archive
First, make sure to back up you blog using the Export function.
If you’re switching the IA of a weblog you’ve been updating for a while, it’s important not to break all of your old links. Although all of your pages will link up properly within the microcosm of your own blog, other people out there may have linked to an entry you made, so don’t delete your archives.
Even better, you can redirect users coming to your old archive pages, either via a search engine or external link, using a META tag or a link on the page. (I don’t think there’s a way to do this with Apache’s mod_rewrite, at least not given my limited knowledge of how rewrite works.)
To make this change, click on the Templates button, then click the Individual Entry Archive to update it. Now, copy and paste the following line in the template, making sure that it’s within the HTML head tags:
<meta http-equiv="refresh" content="10;url=<$MTBlogURL$><$MTArchiveDate format="%Y/%m/"$><$MTEntryTitle dirify="1"$>.html">
This will automatically redirect most browsers to the appropriate page once you re-configure the architecture.
You can also include a link within the body of the template that user’s can click on to redirect themselves:
<a href="<$MTBlogURL$><$MTArchiveDate format="%Y/%m/"$><$MTEntryTitle dirify="1"$>.html">Redirect to updated archive</a>
Save the archive and rebuild your site, making sure to rebuild all the files.
Better, faster, stronger
Now, I’m assuming that your blog is set up to use a single archive directory, like the one described above as the example of a bad IA. My blog has an archive directory named, cleverly, archives.
Go to the Weblog Config menu of your Movable Type system. You’ll need to change the archive directory from archives so that it matches the root directory of your blog. For most setups, that should simply be deleting archives from the end of the specified paths. Here’s a before and after example:
Before
Local Archive Path: /username/public_html/blog/archives
Archive URL: http://www.mysite.com/blog/archives/
After
Local Archive Path: /username/public_html/blog
Archive URL: http://www.mysite.com/blog/
Click Save, but do not rebuild your site yet.
Astute readers will note that this would end up dumping all of your archives in your weblog’s root directory. However, we’re going to use Movable Type template tags to tell the system where to build your archive directories for a better architecture.
While still in the Weblog Config menu, click on the Archives link near the top of the page. There should be four columns — Archive Type, Template, Archive File Template, Del — defining how Movable Type archives your entries. The default is to create individual and monthly entries.
In the row for individual archives, enter the following in the Archive File Template column:
<$MTArchiveDate format="%Y/%m/"$><$MTEntryTitle dirify="1"$>.html
Then, enter this in the same column for the monthly archive row:
<$MTArchiveDate format="%Y/%m/index.html"$>
Your config screen should look something like this.
Click Save.
The changes detailed above tell Movable Type to build date-based directories for your archives and name the archive files according to the title of your entry. The dirify="1" parameter translates your entry title into a format that is suitable for a file or a directory name. It will even parse out funky characters like apostrophes and question marks that aren’t allowed in file names.
Now, rebuild your site, making sure to rebuild all files. It might take a minute if you have a lot of entries. When it’s done, your weblog will have a much improved information architecture, will keep all of your old files in place to avoid the scourge of link rot, and you’ll be helping to make the blogosphere a more beautiful place.
Finally, one quick nod to John Gruber, Mac pundit extraordinaire, who’s own incredibly elegant blog provided the inspiration for me to figure this out for myself.
Enlightened commentary
Contribute brilliance of your own
Trackback
http://www.ibiblio.org/jimray/cgi-bin/mt/mt-tb.cgi/4 ?