Tagging In Subtext

With the announcement of the 1.9.5 release of Subtext, I thought I should talk about the new tagging and tag cloud feature. You can see it in action in the sidebar of my site.

A Tag To implement tagging, we followed the model I wrote about before. Tags do not replace categories in Subtext. Instead, we adopted an approach using Microformats.

We see categories as a structural element and navigational aid, whereas we see tags as meta-data. For example, in the future, we might consider implementing sub-categories like WordPress does.

The other reason not to implement tags as categories is that most people create way more tags than categories and blog clients are not well suited to deal with a huge number of categories.

To create a tag, simply use the rel-tag microformat. For example, use the following markup...

<a href="http://technorati.com/tag/ASP.NET" rel="tag">ASP.NET</a>

...to tag a post with ASP.NET.

Please note that according to the microformat, the last section of the URL defines the tag, not the text within the anchor element. For example, the following markup...

<a href="http://technorati.com/tag/Subtext" rel="tag">Blog</a>

...tags the post with Subtext and not Blog.

Also note that the URL does not have to point to technorati.com. It can point to anywhere. We just take the last portion of the URL according to the microformat.

Technorati tags: , ,

What others have said

Requesting Gravatar... Citizen Parker May 18, 2007 4:22 PM
# re: Tagging In Subtext
What would be your thoughts then on adding a dedicated button for this to the Subtext WYSIWYG editor?

That way I could just click to insert a tag rather than switching to source view momentarily and copying / pasting a tag from somewhere else, as I'm currently doing with 1.8.5 .
Requesting Gravatar... Citizen Parker May 18, 2007 4:34 PM
# re: Tagging In Subtext
Er, that should have of course been "1.9.5"
Requesting Gravatar... Haacked May 18, 2007 5:47 PM
# re: Tagging In Subtext
@Citizen Parker - Would love to have someone submit a patch with that included. *hint* *hint*.
Requesting Gravatar... rokNET.org May 21, 2007 10:39 PM
# A little about LINQ
A little about LINQ
Requesting Gravatar... Dorfer Aug 28, 2007 2:41 PM
# re: Tagging In Subtext
It's too bad you can't link tags back into your own subtext install. For example if I wanted a tag to just take me to my tag page for it at the standard subtext tag url on my blog (ie http://myblog.com/Tag/Sometag/default.aspx) the thing which is actually recorded as the tag is default.aspx. Remove the default.aspx and you get a broken link.

Forgive me if there is some part of blogging lore which says you must link to Technorati and not back to your own site for tags; I am not much of a blogger...
Requesting Gravatar... Haacked Sep 03, 2007 12:36 AM
# re: Tagging In Subtext
Yeah, I'd personally like this too. Part of it is a problem with how IIS 6 sucksworks. We'll come up with something as best we can.
Requesting Gravatar... Marcel Marchon Sep 05, 2007 11:54 PM
# re: Tagging In Subtext
<blockqupte>Part of it is a problem with how IIS 6 sucksworks.

Forgive me for being ignorant, but couldn't that easily be achieved with a wildcard mapping?
Requesting Gravatar... Haacked Sep 06, 2007 12:17 AM
# re: Tagging In Subtext
@Marcel Yes, but wildcard mappings in IIS 6 is fraught with problems. Not to mention it's yet another installation step.
Requesting Gravatar... jphilip Sep 13, 2007 8:51 PM
# re: Tagging In Subtext
This way of adding tags is really not practical for regular people (Non geeks)
At least, to be able to link back to the blog's own tag page, the ParseTags method only needs to discard the /Default.aspx part of the URL if it is present as in the code bellow.
But really the poster should have the option to just type the tags in a text box and have subtext do the rest.
public static List<string> ParseTags(string html)
{
Regex relRegex = new Regex(@"\s+rel\s*=\s*(""[^""]*?\btag\b.*?""|'[^']*?\btag\b.*?')", RegexOptions.IgnoreCase | RegexOptions.Singleline);
Regex hrefRegex = new Regex(@"\s+href\s*=\s*(""(?<url>[^""]*?)""|'(?<url>[^']*?)')", RegexOptions.IgnoreCase | RegexOptions.Singleline);
Regex anchorRegex = new Regex(@"<a(\s+\w+\s*=\s*(?:""[^""]*?""|'[^']*?')(?!\w))+\s*>.*?", RegexOptions.IgnoreCase | RegexOptions.Singleline);

List<string> tags = new List<string>();

foreach (Match m in anchorRegex.Matches(html))
{
string anchorHtml = m.Value;
if (!relRegex.IsMatch(anchorHtml))
continue;

Match urlMatch = hrefRegex.Match(anchorHtml);
if (urlMatch.Success)
{
string urlStr = urlMatch.Groups["url"].Value;
if (urlStr.ToLower().EndsWith("/default.aspx"))
urlStr = urlStr.Substring(0, urlStr.Length - 13);
Uri url;
if (Uri.TryCreate(urlStr, UriKind.RelativeOrAbsolute, out url))
{
string[] seg = url.Segments;
string tag = HttpUtility.UrlDecode(seg[seg.Length - 1].Replace("/", ""));
if(!tags.Contains(tag))
tags.Add(tag);
}
}
}
return tags;
}
Requesting Gravatar... Haacked Sep 14, 2007 9:19 AM
# re: Tagging In Subtext
Hi JPhilip, I agree and we're working on a fix. Thanks for the code submission. If you wouldn't mind, you should consider submitting a patch. Scott Hanselman wrote up instructions here.
Requesting Gravatar... jphilip Sep 14, 2007 2:04 PM
# re: Tagging In Subtext
Hi Phil,
I just finished a patch including a FCKEditor plugin that adds a button to the Editor's toolbar, prompts the user for the tags and appends external tag links (to Technorati or other) and/or internal tag links to the blog's tag page.
All is configurable through the subtextconfig.js file.
The javascript to find the blog's url in a multi blog install is not very elegant but it works in my case, maybe you will have something better.
I will post the patch right away.
Requesting Gravatar... Dorfer Sep 17, 2007 9:35 AM
# re: Tagging In Subtext
I know jphillip worked around the whole "/default.aspx" local url problem via javascript, but it seemed odd to me there was no way to handle directory default urls (eg myblog.com/tags/sometag/) more easily in asp.net. I looked into it quick (or rather google looked into it for me) and it would appear you can do such a thing via a couple more http handlers in the web.config file. See http://www.codeproject.com/useritems/handledirectory.asp

I haven't actually tested it, but it seems pretty straightforward to me. Just thought I would pass it along.
Requesting Gravatar... Dorfer Sep 17, 2007 9:45 AM
# re: Tagging In Subtext
Forgive me for the double post, but I see the problem in my previous comment-- the need for the wildcard mapping in IIS, which you guys had already covered. My bad, its been too long since I dealt with the fun of web design...
Requesting Gravatar... Haacked Sep 17, 2007 12:40 PM
# re: Tagging In Subtext
Yeah, we're really really trying to avoid wildcard mappings in IIS. We're holding out until IIS 7 is more widely adopted. :)
Requesting Gravatar... Anonymous May 23, 2008 9:31 PM
# re: Tagging In Subtext
This may be a stupid question but "where" are you putting these micro tags, in a post using the Subtext editor? Or are you going in the source code to add this in a specific cloud control? I'm not familiary with tagging much.
Requesting Gravatar... Anonymous May 23, 2008 9:38 PM
# re: Tagging In Subtext
Nevermind, just downloaded Windows Live Writer via your other post. Works like a charm!

What do you have to say?

(will show your gravatar)
Please add 1 and 1 and type the answer here: