There was a discussion regarding naming of posts in a CommunityServer forum (a surprisingly unknown feature of CS::Blogs, though even dotText .96 supported it). CS replaces spaces with underscores. However, Jonathan stated that Google prefers hyphens to underscores. So I tried to use hyphens in the post name, but I’ve stumbled over two issues:

  1. You cannot enter hyphens in the post’s name edit box because the field validator won’t accept it. The regular expression is defined in the code as [a-zA-Z][1234567890a-zA-Z_\\s]{4,250}, i.e. only letters, digits, underscores, and white-spaces are allowed. To enable hyphens as well, you have to change line 155 in Blogs\WeblogPosts.cs to

    public static readonly string PostNamePattern = "^[a-zA-Z][1234567890a-zA-Z\\-_\\s]{4,250}$";

    and re-compile CommunityServer.Blogs.dll.

  2. When you want to visit the post using the named url, you’ll get a 404 error. That’s because the regular expression in SiteUrls.config is defined as ``\w+, i.e. only letters, digits, and underscores. Again no underscores. Fortunately, there's no compilation required, instead change the regular expressions for weblogpostName and weblogarticleName` to:

    <url name="weblogpostName"
        location="weblogs" path="{0}/archive/{1}/{2}/{3}/{4}.aspx"
        vanity="post.aspx?App=$1&amp;y=$2&amp;m=$3&amp;d=$4&amp;PostName=$5" />
    <url name="weblogarticleName"
        location="weblogs" path="{0}/articles/{1}.aspx"
        vanity="post.aspx?App=$1&amp;PostName=$2" />

    (Be careful if your SiteUrls.config differs from the default configuration, e.g. if you have used Ken Robertson’s SiteUrls Generator.)

If you’re using ScottW’s auto-naming module, you can skip step one including the re-compilation and just edit your SiteUrls.config.


jayson knight

Ok fantastic…I’ll try and get this up and running.

One more question for you (and forgive me if the answer is obvious)…how do you preserve whitespace in comments on your CS install? Comments on mine get all squished together (as you’ve seen from your code comment on my site). Very annoying and I gave up tracking it down months ago.

jayson knight

Quick question about this: How is other punctuation handled in the post title? i.e. I’d say more than half of my posts have formats like so:

First part of the title – second part


first part of the title…second part

I’m the first to admit that I’m regex impaired…how would I go about stripping out all punctuation and still have the hyphens?

Second question: Is there a way to get both formats running on the same installation? I wouldn’t want to lose my old trackbacks with the default format.

Thomas Freudenberg

Hi Jayson.

Regarding your first question, it depends how you name your posts. You can only use letters, digits, underscores, and hyphens. There might be some special characters you might use, but no ‘#’, ‘&’ or ‘?. You may use Scott’s auo-name module, which generates the name from the title automatically. However, Scott’s code is only a proof-of-concept, e.g. it lacks the removal of special characters.

I can reassure you that referencing your post by id and by name can co-exist. If you have look at your SiteUrls.config, you can find weblogpostId and weblogpostName. The first one handles the request, if the url contains ony digits. If this doesn’t match, the second one will handle posts by their name.

jayson knight

Haha…it must be related to the skin I’m using then (and it’s driving me CRAZY). I’ll ping the guy who authored the skin and see if he has any input…if you find anything from your end pls let me know :-).

Leave a Comment

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