This morning's entry on categories got me thinking and I decided to try generating a tag cloud based on the keywords I put on entries. Here is the result. I like it because it gives an immediate feel for which topics I spend the most time on. The cloud doesn't show tags I used just once. To create the page, I followed Al-Muhajabah's instructions with a few modifications.

  • I'm careful to separate my tags by commas or whitespace, so I replaced
    $wordlist = preg_split(
      '/\\s*[\\s+\\.|\\?|,|(|)|\\-+|\\'|\\"|=|;|×|\\$|\\/|:|{|}]\\s*/i', 
      $string);
    
    with
    $wordlist = preg_split('/\\s+|,/i',$string);
    
    The longer regexp was breaking things up more than I wanted and I was ending up with tags that weren't tags I'd created.
  • I modified some the font sizes to make them 25 points bigger all around. The smallest font wasn't readable, at least in Firefox.
  • I changed if ($count >= 1) to if ($count >= 2) on the grounds that if I've only used a tag once, it's probably not all that important.
  • Al-Muhajabah uses a SearchFields option in the search URL that doesn't appear to be supported by MovableType. As an alternate, I used the SearchElement option which is supported, but not for keywords. I modified the _search_hit function in $MTHOME/lib/MT/App/Search.pm to support the keyword field like so:
    sub _search_hit {
      my($app, $entry) = @_;
      my @text_elements;
      if ($app->{searchparam}{SearchElement} ne 'comments') {
          @text_elements = 
              ($entry->title, $entry->text, $entry->text_more,
               $entry->keywords);
      }
      if ($app->{searchparam}{SearchElement} ne 'entries') {
          my $comments = $entry->comments;
          for my $comment (@$comments) {
              push @text_elements, 
                     $comment->text, $comment->author,
                     $comment->url;
          }
      }
      if ($app->{searchparam}{SearchElement} eq 'keywords') {
          @text_elements = ($entry->keywords);
      }
      return 1 
         if $app->is_a_match(
                join("\
    ", map $_ || '', @text_elements));
    }
    

This seems to work pretty well, giving the right results in the search. I'm going to monitor it for a while and eventually remove categories from my blog.


Please leave comments using the Hypothes.is sidebar.

Last modified: Thu Oct 10 12:47:18 2019.