After having to roll my own tag cloud generator for my blogs (I'm old-school, so I don't have access to a blog layout engine with prebuilt widgets), I thought I'd clean up the code and share it. So, it's in this new repository I just created on GitHub.
Usage is pretty simple; copy the JS (and optional CSS) to your server, and link to them from your blog code like so:
The parameters on the makeCloud() method are:
- tags: the object hash mentioned above
- baseUrl: the URL that should serve as the base for all tag links
- minCount: minimum number of times tag must be used to show up in the cloud (defaults to 0)
- minSize: minimum font size for tags in the cloud (defaults to 1em)
- max: maximum font size for tags in the cloud (defaults to 4.5em)
- delim: delimiter(s) to insert between tags in the cloud (defaults to 1 space)
- shuffle: boolean value that controls if the tags get shuffled in random order, or sorted (defaults to false)
That's about all there is to say about it. The basic math for determining the tag size is taken almost verbatim from the Wikipedia page on tag clouds, just slightly tweaked to allow for a minimum font size. Surely there are other customizations that could be made, and ideally this would be implemented as a Dojo/plugd-style plugin. I'll leave that for an exercise at a later date.
--Edit: I inadvertently forgot to strip out the <script> tags from the sample code blocks up above, and they were getting run! D'oh!