Google Sitemap

Overview

Sitemaps facility in farcry lets you dynamically create a google sitemap with just a few lines of code.

Navigation Sitemap

Your classic Google Sitemap should encapsulate all the navigation points in your information hierarchy. For that we need to generate an extract of the Navigation Folders (aka dmNavigation content type).

In FarCry terms, anything that is essentially a list of content items of a certain type should be built as a "type webskin" (aka listing view) of the principle content type.

Create a webskin under /webskins/dmNavigation or under another type if needed. In this example we'll call it displayTypeSiteMap.cfm. Add the following code.

./webskins/dmNavigation/displayTypeSiteMap.cfm
<cfsetting enablecfoutputonly="true" /> 
<!--- @@displayname: Google Sitemap --->
<!--- @@description: Generates a Google Sitemap for all Navigation content items. --->
<!--- @@cacheStatus: 1 --->
<!--- @@cacheTimeout: 60 --->
<!--- @@fuAlias: sitemap --->

<!--- 
 // build sitemap xml
--------------------------------------------------------------------------------------------------->
<cfset oSiteMap=createObject('component', 'farcry.core.packages.googleSiteMap.sitemap').init()>
<cfset stSiteConfig=structNew()>
<cfset stSiteConfig.domainName="#cgi.server_name#">

<cfset xml=oSiteMap.generate(stSiteConfig=stSiteConfig,siteMapType="siteMap", types="dmNavigation")>

<!--- 
 // view
--------------------------------------------------------------------------------------------------->
<CFHEADER NAME="content-disposition" VALUE="inline; filename=dmnavigation.#now()#">
<cfheader name="Content-Type" value="text/xml">
<cfoutput>#xml#</cfoutput>

<cfsetting enablecfoutputonly="false" />

Multiple Content Types

In the types argument passed to the oSiteMap object you have a list of types. The sitemap generator will then add all of those type into the sitemap.

You then point Google to this url e.g http://www.mysite.com/dmNavigation/sitemap. Notice the <!--- @@fuAlias: sitemap ---> in the code above, this allows you to use 'sitemap' in the url instead of the full name of the view (ie. displayTypeSiteMap).

News Sitemap

The sitemap generator will also generate a "news sitemap". Google have a special format for organisations that put out regular news-like content, and with a slight modification you can generate this type of sitemap as well.

For example, ./webskins/dmNews/displayTypeSiteMap.cfm
<cfsetting enablecfoutputonly="true" /> 
<!--- @@displayname: Google News Sitemap --->
<!--- @@description: Generates a Google News Sitemap from dmNews content items. --->
<!--- @@cacheStatus: 1 --->
<!--- @@cacheTimeout: 60 --->
<!--- @@fuAlias: sitemap --->

<!--- 
 // build sitemap xml
--------------------------------------------------------------------------------------------------->
<cfset oSiteMap=createObject('component', 'farcry.core.packages.googleSiteMap.sitemap').init()>
<cfset stSiteConfig=structNew()>
<cfset stSiteConfig.domainName="#cgi.server_name#">
<cfset stSiteConfig.newspublication="#application.fapi.getConfig('general','sitetitle', '#application.applicationname#')#">

<cfset xml=oSiteMap.generate(stSiteConfig=stSiteConfig,siteMapType="newsSiteMap",newsTypes="dmNews:publishDate")>

<!--- 
 // view
--------------------------------------------------------------------------------------------------->
<CFHEADER NAME="content-disposition" VALUE="inline; filename=dmnews.#now()#">
<cfheader name="Content-Type" value="text/xml">
<cfoutput>#xml#</cfoutput>

<cfsetting enablecfoutputonly="false" />

In the newsTypes argument passed to the oSiteMap you can pass in a list of types but you must also pass in the name of the property for publishdate.

You then point google sitemaps to this url e.g http://www.mysite.com/dmnews/sitemap

Other Options

You can also overwrite the default method of getting the data by adding getSiteMapData or getNewsSiteMapData method in your type

The sitemap generator also deals with sitemap indexes but more on that later