We noticed recently that if someone posted a comment on our blog with a really long URL it wouldn’t wrap and as a result it would throw off the whole template. To address this we wrote a custom tag that uses regular expressions to search for long URLs in the comment area and cut off the text portion.
To get an idea of the problem, take a look at this page, the original page before we implemented URL shortening.
The custom tag, cf_ShortenLongURLs, searches for simple URL links in the contained content like those auto-produced by MovableType in entry comments. It then replaces the displahyed portion with a chopped off version and three dots. For good measure, I also included the ability to add an attribute to the links which I use to force target=”_blank”.
\1",
textToFix,
startPos,
true)>
" & shortUrl & "">
It’s a pretty straightforward tag. It has two optional attributes for the cutoff length and new link attributes. Implemented inside MovableType, it looks like this:
<MTComments> <div class="comments-body"> <cf_ShortenLongUrls> <$MTCommentBody$> </cf_ShortenLongUrls> <span class="comments-post"> Posted by: <$MTCommentAuthorLink spam_protect="1"$> at <$MTCommentDate$></span> </div> </MTComments>
After applying, the pages with long links are displayed nicely, as you can see here.
Can it be used with RSS data? It could be quite useful to me.
Sure, you can use it when displaying data retrieved through RSS. That’s a good idea since you won’t know if the content has URL’s that will throw your design out of wack. Just make sure you use it when displaying the RSS content to an end user and not when generating RSS for automatic consumption–the raw RSS source should be original URL without the shortened version.
Well beard bust rake churn free slots online cards spice rank cripple.
big thank