How to Generate Google Sitemaps for blojsom-Based Blogs

As I mentioned yesterday, I finally got around to building a Google Sitemap for this blog. What follows are instructions for other blojsom owners to do the same, so it probably won't interest most of you. I'd like to remind my readers who use WordPress that the same functionality can be achieved by installing the Google Sitemaps Generator for WordPress, which I use all the time on my other blogs.

A New Flavor

At first I thought I'd have to write a new blojsom plugin in order to get Sitemaps functionality, which is why I put it off for so long. But eventually I had no choice to start the project, as I really needed to have the pages of Make Easy Money with Google and AdSense properly indexed by Google.

Anyhow, I was learning how to build blojsom plugins when it occurred to me that I was doing it all wrong: I could achieve the same thing much more easily with a new blojsom flavor. Hence the “sitemap” flavor was born. Access this URL:

http://www.memwg.com/blog/adsense/?flavor=sitemap

And you'll see a Google Sitemap for the blog.

Creating the Sitemap Flavor

Adding the sitemap flavor is trivial. In your blog's directory (usually WEB-INF/blog-name) there are two files to modify. Add the following line to flavor.properties:

sitemap=sitemap.vm, text/xml;charset=UTF-8

Similarly, add this line to plugin.properties:

sitemap.blojsom-plugin-chain=string-utilities, all-entries

These changes define a new flavor, “sitemap”, that ends up running the Velocity file “sitemap.vm” after first running the “string-utilities” and “all-entries” plugins. You'll need to restart the blojsom webapp before continuing.

The Velocity Sitemap Template

We're almost done. In the blog's templates directory you need to create sitemap.vm with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="gss.xsl"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">

 <url>
   <loc>$BLOJSOM_BLOG.getBlogURL()</loc>
   <priority>1.0</priority>
   <changefreq>hourly</changefreq>
 </url>
#foreach ($entry in $BLOJSOM_PLUGIN_ALL_ENTRIES)
 #DatelessFriendlyPermalink($entry)

 <url>
   <loc>$BLOJSOM_PLUGIN_STRING_UTILITIES.escapeString($entryLink)</loc>
   <lastmod>#FormatDate($entry "yyyy-MM-dd")</lastmod>
   <changefreq>weekly</changefreq>
   <priority>0.5</priority>
 </url>
#if ($BLOJSOM_COMMENTS_ENABLED.booleanValue() &&
$entry.supportsComments() &&
( $entry.getNumComments() > 0 ) && ($entry.getMetaData() &&
!$entry.getMetaData().containsKey("blog-entry-comments-disabled")))

 <url>
   <loc>$BLOJSOM_PLUGIN_STRING_UTILITIES.escapeString("$entryLink?page=comments")</loc>
   <changefreq>weekly</changefreq>
   <priority>0.1</priority>
 </url>
#end
#end

</urlset>

This template is actually very simple. First, it creates a <url> block for the blog root, in this case http://www.memwg.com/blog/adsense/. Then it loops through all the blog entries (added to the flavor's context via the “all-entries” plugin) and adds <url> blocks for each blog entry and, for the entries with comments, each comment page.

Once the sitemap.vm file is created you should be able to access your sitemap using the URL:

http://www.yourdomain.com/blog/blogname/?flavor=sitemap

The Sitemaps Index

We're almost done. Although the sitemap we generate is valid, it's in the wrong spot. The Sitemaps protocol requires you to place the sitemaps file at the root of your site. Rather than moving it, though, we can cheat and use a “sitemap index” file to refer to it instead. For example, this is the sitemap index for memwg.com:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">
  <sitemap>
    <loc>http://www.memwg.com/blog/adsense/?flavor=sitemap</loc>
  </sitemap>
</sitemapindex>

If you had multiple blogs running on the same site, you'd add a block for each sitemap. You could also create a sitemap for the non-blog pages and add it here as well.

You can now submit your sitemap to Google.

Sponsored Link: Visit The HDTV Shoppe for all your HDTV needs.

Eric Giguere wrote Make Easy Money with Google, which is not the spammy get-rich book you might think it is, and is about to release (finally) Uncommon AdSense, a book aimed at more experienced AdSense publishers. And no, it won't be overpriced.

Socialize This Post (Please!)

Add to OnlywireAdd to Onlywire

Tags

Comments

2 Responses to “How to Generate Google Sitemaps for blojsom-Based Blogs”

  1. Vinny on August 7th, 2007 1:49 pm

    Good tutorial for making that sitemap. Esp for those of us still stuck on version 2 of blojsom. One thing though, you need to tell people that :
    $BLOJSOM_PLUGIN_STRING_UTILITIES.escapeString(”$entryLink?page=comments”)

    must have NO line breaks or they will get nasty error about some unknown character “\n” from the velocity parser.

  2. Eric Giguere on August 7th, 2007 5:45 pm

    Yeah, it’s pretty picky. I’ve moved away from Blojsom, however, so I don’t have these issues anymore :-)

Subscribe without commenting