Add rel="nofollow" to .Text comments

,

Today Google, Yahoo, MSN Search, and other search operators announced their support of the rel="nofollow" attribute for <a href="..." /> tags. Adding this attribute indicates the search crawlers, that the specific links should not contribute to the linked site’s page rank. This might help fighting comment spam, since overwhelming blogs with comments containing links to any pharmaceutical site won’t increase their search rank.

Whether this will help to fight comment spam or not, time will show. Anyway, I’ve written a small plug-in for .Text, which adds the mentioned attribute to all links in comments.

Some time ago Scott Watermasysk has described who to add custom entry handlers to .Text v.96. According to these instructions, my entry handler looks as follows:

public class NoFollowFormatHandler : IEntryFactoryHandler
{
    public NoFollowFormatHandler()
    {}
    public void Configure()
    {}
    public void Process(Entry entry)
    {
        entry.Body = ReformatLinks(entry.Body);
    }
    private string ReformatLinks(string text)
    {
        return text.Replace(
            "<a target=\"_new\" href=\"",
            "<a target=\"_new\" rel=\"nofollow\" href=\"");
    }
}

Afterwards, you have to add this handler to the event handler configuration section in your web.config, in fact after the default handler:

<EntryHandlers>
    <EntryHandler
        type="Dottext.Framework.EntryHandling.CommentFormatHandler, Dottext.Framework"
        postType="Comment" processAction="Insert" processState="PreCommit"
        isAsync="false" />
    <EntryHandler
        type="Dottext.NoFollow.NoFollowFormatHandler, Dottext.NoFollow"
        postType="Comment" processAction="Insert" processState="PreCommit"
        isAsync="false" />
    <EntryHandler
        type="Dottext.Framework.EntryHandling.CommentDeliveryHandler, Dottext.Framework"
        postType="Comment" processAction="Insert" processState="PostCommit"
        isAsync="true" />
    ...

That’s it. You may either download the source code, or just get the compiled assembly and copy it to your bin folder. Add the handler in the web.config, and all links in new comments will have the rel="nofollow" attribute.

Be aware, that this solution targets .Text v.96 only. V.95 does not have entry handlers, so please don’t bother me with asking for a .95 version.

Comments

Thomas Freudenberg

Thanks for your comment, Dave. It’s sad that since more than one year there hasn’t been any .Text release. Well, except those CS betas, but that’s another story.

You have made great enhancement to .95, and I’ve planned to incorporate many of them into my .96 installation.

Chee Wee

Hi,

Do you have a copy of the SQL scripts, stored procedures, and other modifications necessary to update the database schema for .Text 0.95 to 0.96?

If you have, could I have it?

Dave Burke

Great post, Thomas. Excellent description of implementation for 0.96. I was going to ask you for a 0.95 version, but after reading the last line I decided not to. :-)

This is interesting, but I never thought comment URLs were a problem. Maybe I don’t yet fully understand the concept. Bogus trackbacks and referrals, yes, but not comments.

If I implement a 0.95 version I’ll let you know. Thanks!

Dave Burke

Just following your lead, Big Guy. From what I’ve seen so far of .96, there’s a ton of stuff in there that will keep us interested for a while! Yeah, its been a long weird year in the life of .text with Telligent and CS::blogs and all. But I better watch what I say though, since I see ScottW reads your blog. :-)

Thanks for the kind words. Talk to you soon.

Leave a Comment

Your email address will not be published. Required fields are marked *

Loading...