Saturday, March 6, 2010

TypePad Sitemap Template with More Than 100 Entries

[Update, 3/13/2012: This blog is now on Google’s Blogger platform. However, I’ve kept this post around in case it helps those still on Typepad.]

Sitemaps are a way to help search engines find pages on a Web site. This blog has its own Sitemap, which I noticed was limited to displaying the last 100 blog entries. That’s bad, because I have more than 100 entries, and Google was losing track of some of the early ones.

A Sitemap can have up to 50,000 URLs, so I emailed the support desk of TypePad (the service that hosts this blog), asking what the problem was. The answer was, TypePad’s suggested template for Sitemaps uses a template tag called MTEntries, which is limited to showing 100 entries. That’s confusing because the relevant part of the suggested template says, as of March 6, 2010, <MTEntries lastn=“1000”>. Oh well. The person who answered my support question said TypePad was evaluating raising the limit.

It should be raised, or TypePad should provide some other means for directly communicating the presence of more than 100 blog entries. But in the meantime, I’ll share a quick workaround I devised. It’s ugly, but it works for this blog’s 250-odd posts.

In the suggested Sitemap template, I duplicated the block of XML responsible for generating the list of blog-entry URLs. I set the first block’s “lastn” parameter to 100. For the duplicate, I also set “lastn” to 100 but I added an “offset” parameter of 100. That means the first block gets the 100 most recent entries, and the second block gets the 100 next most-recent entries. Then I created another duplicate block, “lastn” of 100, “offset” of 200.

That’s all I needed (for now). The resulting Sitemap had all 250 postings. I don’t know how far this hack scales up, but I figured I’d share the idea. May it be useful for the hopefully short time between when this was written and when TypePad better supports Sitemaps.

FYI, this is the relevant block in the suggested Sitemap template (as of March 6, 2010):

<MTEntries lastn=“1000”>
<url>
<loc><$MTEntryPermalink encode_xml=“1”$></loc>
<lastmod><$MTEntryDate format=“%Y-%m-%d”$></lastmod>
<priority>0.8</priority>
</url>
</MTEntries>

Replace that block with the following three blocks:

<MTEntries lastn=“100”>
<url>
<loc><$MTEntryPermalink encode_xml=“1”$></loc>
<lastmod><$MTEntryDate format=“%Y-%m-%d”$></lastmod>
<priority>0.8</priority>
</url>
</MTEntries>

<MTEntries lastn=“100” offset=“100”>
<url>
<loc><$MTEntryPermalink encode_xml=“1”$></loc>
<lastmod><$MTEntryDate format=“%Y-%m-%d”$></lastmod>
<priority>0.8</priority>
</url>
</MTEntries>

<MTEntries lastn=“100” offset=“200”>
<url>
<loc><$MTEntryPermalink encode_xml=“1”$></loc>
<lastmod><$MTEntryDate format=“%Y-%m-%d”$></lastmod>
<priority>0.8</priority>
</url>
</MTEntries>

If you want to try more blocks, the pattern for doing so should be evident. The only thing you need to change is the “offset” in the first line of each additional block. Just increment it by 100.

One final note: The generated sitemap.xml document did not change after I saved the changes to my Sitemap template. This was apparently due to caching, which a template-save should have immediately overridden but did not. I confirmed this by copying the text of my changed template to a new template, sitemap2.xml, which generated the correct XML file. The next day, when I checked my sitemap.xml again, it had updated to the correct XML, so the cache apparently needs time to detect changed templates.

No comments:

Post a Comment