A new year. Time to look around the house and tidy up. I had grandiose plans for some new weblog features here at CDB, but like many year-end resolutions, fell a bit short.
One thing I did (and partially messed up) was to change the URL and location of the individual archives created by MovableType. Out of the box, you typically end of with your blog postings having URLs such as:
e.g. creating sequentially numbered URLs which are nice if you are a database and like references such as “000379”, but the URL itself says nothing about the content at all. I decided to make some changes, with the resulting same post now residing at:
Which lets you know by looking at the URL (with some guessing) that this post is was made December 22, 2003 and has something to do with RSS and a winter festival (maybe). Here was the path..
This started out with some references to and reading Mark Pilgrim’s explanation of how he achieved “Cruft-Free URLs in MovableType”, with the goal of achieving shortened but meaningful URLs. His post explains more or less what I did, although he goes one step farther than I did in actually taking the steps to make the ending “.html” not used. I can live with that “cruft” in my URLs because by itself it suggests the URL is a pointer to a web page.
The first part is just changing the MovableType setting so it will create individual entries in a structured set of directories based on the date and the title of your post as opposed to just naming them by an increasing number and tossing will-nilly into your archives directory.
To make this basic change, go to the Weblog Config area in MovableType, click the “Archiving” navigation link. Go to the first entry area for Individual Archive. What many do not realize is that you can use MovableType template tags in the Archive File template field, so the names of the files MT creates can be dynamically generated.
A basic change to create archives based on the date and the title of an entry your be:
<$MTArchiveDate format="%Y/%m/%d"$>/<$MTEntryTitle dirify="1"$>.html
The first part converts the date the entry has made (December 22, 2003) into a directory string 2003/12/22, followed by another forward slash, and then converting the title of the post (MTEntryTitle) into a URL friendly file name (that part that says “dirify=1” says convert all spaces to underscore).
The result is the post titled “RSS WinterFest 2004- Party at Dave’s?” is now a file in my archives directory stored at:
Note that the dirify=1 not only converted spaces in the title to “_”, it made all the letters lower case, and dropped things that do not make good file names (apostrophe, and the question mark).
This works nicely, but you end up with some horribly long URLs for some long-winded post titles. That is where Dive into Mark’s suggestion to use Brad Choate’s MT -IfEmpty plugin that can do a logical check whether I have entered any keywords into the MT entry. For the most part I had never entered them, so Mark’s suggestion for an individual archive is to use this plugin to name entries that have no keywords or to use the keywords if they exist to make a shortened file name:
<$MTArchiveDate format="%Y/%m/%d"$>/<MTIfEmpty var="EntryKeywords">
<MTIfNotEmpty var="EntryKeywords"><$MTEntryKeywords dirify="1"$></MTIfNotEmpty>.html
The MTIFEmpty plugin allows us to have two branching results depending if I had entered any keywords.
So for the example above, I just added keywords “rss winterfest”, and rebuilding the archives gives me the desired:
The nice thing about this series of changes was that all the archive files created are new files, leaving the old URLs in place in case they were bookmarked.
Note that my archive naming example uses the *.html extension above, I had neglected that by mistake resulting in some archive posts that had rendered as raw HTML (Thanks Stephan and Pat for catching that boo-boo)
The post "Reorganizing the Dog/Blog House" was originally zapped with 10,000 volts and declared "It's ALIVE" by Dr. Frankenstein at CogDogBlog (http://cogdogblog.com/2004/01/reorganizing-the/) on January 12, 2004.