Tagging In Subtext

0 comments suggest edit

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.

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.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



18 responses

  1. Avatar for Citizen Parker
    Citizen Parker May 18th, 2007

    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 .

  2. Avatar for Citizen Parker
    Citizen Parker May 18th, 2007

    Er, that should have of course been "1.9.5"

  3. Avatar for Haacked
    Haacked May 18th, 2007

    @Citizen Parker - Would love to have someone submit a patch with that included. *hint* *hint*.

  4. Avatar for rokNET.org
    rokNET.org May 21st, 2007

    A little about LINQ

  5. Avatar for Dorfer
    Dorfer August 28th, 2007

    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/Somet... 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...

  6. Avatar for Haacked
    Haacked September 2nd, 2007

    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.

  7. Avatar for Marcel Marchon
    Marcel Marchon September 5th, 2007

    <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?

  8. Avatar for Haacked
    Haacked September 5th, 2007

    @Marcel Yes, but wildcard mappings in IIS 6 is fraught with problems. Not to mention it's yet another installation step.

  9. Avatar for jphilip
    jphilip September 13th, 2007

    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))
    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("/", ""));
    return tags;

  10. Avatar for Haacked
    Haacked September 13th, 2007

    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.

  11. Avatar for jphilip
    jphilip September 14th, 2007

    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.

  12. Avatar for Dorfer
    Dorfer September 16th, 2007

    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/...
    I haven't actually tested it, but it seems pretty straightforward to me. Just thought I would pass it along.

  13. Avatar for Dorfer
    Dorfer September 16th, 2007

    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...

  14. Avatar for Haacked
    Haacked September 17th, 2007

    Yeah, we're really really trying to avoid wildcard mappings in IIS. We're holding out until IIS 7 is more widely adopted. :)

  15. Avatar for Anonymous
    Anonymous May 23rd, 2008

    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.

  16. Avatar for Anonymous
    Anonymous May 23rd, 2008

    Nevermind, just downloaded Windows Live Writer via your other post. Works like a charm!

  17. Avatar for Flavio
    Flavio September 21st, 2008

    Hello, how do I see the tagcloud working on my subtext, I tried a variety of ways does not work.
    Please could someone help me?

  18. Avatar for Anonymous
    Anonymous March 2nd, 2009

    Ok, what if you want the tags in your posts to act just like the cloud. That you don't want it to go to another 3rd party site but simply show the list of posts by that tag.
    If I use a provider, clicking on a tag goes to the provider rather than take them to the list of posts on my site.