This week I added support for Google Sitemaps to my blog. While this isn't in the core BlogCFC install yet, I thought I'd share the code in case others wanted to do it. Right now I've just created a new CFM and dropped the code in there. I will most likely move the generation to a CFC method later on. Also note that I was unable to get the sitemap to verify until I "tricked" google. My file name was, let's say, sitemap.cfm. This refused to validate. I saved the output of my file as test.xml, and that validated immidiately. I hunted around and found a few people who asked if the extension would cause problems for Google. On a whim, I resubmitted by sitemap with this url: (Not the real URL.) This was enough to "fool" Google and allow my sitemap to validate. The code is below.

Note - the code belows has MY url in it. You would obviously want to change that. The "real" code in 4.0 won't require that.

<cfsetting enablecfoutputonly=true showdebugoutput=false>
<cfprocessingdirective pageencoding="utf-8">

<cfset params = structNew()>
<!--- Should be good for a while.... --->
<cfset params.maxEntries = 99999>
<cfset params.mode ="short">

<cfset entries =>

<cfset z = getTimeZoneInfo()>
<cfif not find("-", z.utcHourOffset)>
   <cfset utcPrefix ="-">
   <cfset z.utcHourOffset = right(z.utcHourOffset, len(z.utcHourOffset) -1 )>
   <cfset utcPrefix ="+">

<cfset dateStr = dateFormat(entries.posted[1],"yyyy-mm-dd")>
<cfset dateStr = dateStr &"T" & timeFormat(entries.posted[1],"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") &":00">

<cfcontent type="text/xml"><cfoutput><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="">
   <cfoutput query="entries">
      <cfset dateStr = dateFormat(posted,"yyyy-mm-dd")>
      <cfset dateStr = dateStr &"T" & timeFormat(posted,"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") &":00">