Neil Turner's Blog

Blogging about technology and randomness since 2002

Trimming your titles

Although this is about blogging, I’ve also posted this to Rants because I haven’t had chance to rant in a while. My rant is about blog permalinks with super-long URLs – ‘Sending TrackBack pings indiscriminately makes you a TrackBack spammer’ on Redemption in a Blog is an example of this. (side note: the article is worth a read)

Firstly, I’ll admit this: since changing to using URLs which have the title in, the URLs have got longer, but then I tend to keep my titles pretty short. But, if I were to post an entry called ‘The rather fantastic entry with the unnecessarily long name’, I’d end up with an url like http://www.neilturner.me.uk/2003/Dec/28/ the_rather_fantastic_entry_with_the_unnecessarily_long_name.html. Catchy, isn’t it?

So, ladies and gentlemen, I present to you the trim_to="x" attribute. This global attribute, which should certainly work in Movable Type 2.6+ and probably older versions too, will let you specify x, which is the maximum number of characters to use in the tag’s output. I’ve used it on my template blog since I could forsee the URLs getting quite long, although I made the mistake of selecting 15 characters – 20 is probably a better number.

How do you implement it? Here’s how I would do it: <$MTArchiveDate format="%Y/%b/%d"$>/<$MTEntryTitle dirify="1" trim_to="20"$>.html . Bung that into your archiving configuration and you’re done. I’d do it on this blog if it were not for the fact that it would probably break all the permalinks yet again (if someone can tell me how to implement without doing that then I’d be most greatful).

There’s also the matter of underscores, which I’d love to do without if I could. I’m sure I could use Brad’s Regex plugin to do it but a more basic plugin which would allow me to add a removechars="_" attribute or something would be nice.

6 Comments

  1. I found out about this attribute about 2 minutes after I completely rebuilt all my archives last week and, at this point, I’m not about to setup a massive .htaccess file again to get redirects to work, and I really don’t feel like some some fancy Apache re-writes.
    Why did you write this post about a 10 days ago? 😉

  2. Found you from my referrers listing.
    I have always been thinking how ugly my long URLs look because I tend to like longer descriptive titles. Thanks for pointing out the trim_to attribute – didn’t know that existed! Unfortunately it sorta breaks if it trims in the middle of a word, and makes for somethings incomprehensible URLs. What I would really like is something like that at Simon Willison’s weblog (http://simon.incutio.com/) where you get to actually define the URL of each entry you make. For example, his entry “I’ve ordered my PowerBook” is here -> http://simon.incutio.com/archive/2003/12/20/anticipation.
    If someone knows how to make this work in MT, do let me know!

  3. I don’t know the details but I think you could do this by using the keyword field in MT and then having that field’s contents populate the URL?

  4. xian: Yep, I could, but that’s not what the field was designed for, and certainly other bloggers have used the same argument. Besides, it means that writing an entry requires more effort.
    You’re probably thinking of Mark’s ‘slugs’ post which tells you how to do it.
    Jake: Sorry!

  5. xian: Yeap I read about that somewhere before but didn’t like it for the reason neil mentioned. Besides, MT uses the keyword field to return seaches, plus I have a related entries section which uses those keywords.
    Thanks for mentioning it though! 🙂