-
Notifications
You must be signed in to change notification settings - Fork 24
Description
When using the addLink() method in the HTMLHelperProperty, passing in type=canonical, the output will always return something of the following variety:
<link rel="canonical" type="http://www.foo.com/bar" />
The spec on the tag suggests that the format should include a rel attribute but no type attribute, a la:
<link rel="canonical" href="http://www.foo.com/bar" />
I've created a fix for myself locally by updating the addLink() method with the code below. Unsure if this is the best approach but it works for me.
I'm on
Version: 1.9.0.2823 (Integrity)
Built-on: 2011-07-08 02:11:51
Using Railo 3.3.4.003 final
For reference:
http://en.wikipedia.org/wiki/Canonical_link_element
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=139394
<cffunction name="addLink" access="public" returntype="string" output="false"
hint="Adds code for a link tag for inline use or in the HTML head.">
<cfargument name="type" type="string" required="true"
hint="The type of link. Supports type shortcuts 'icon', 'rss', 'atom', 'html' and 'canonical', otherwise a complete MIME type is required." />
<cfargument name="href" type="string" required="true"
hint="The href path to a web accessible location of the link file." />
<cfargument name="attributes" type="any" required="false" default="#StructNew()#"
hint="A struct or string (param1=value1|param2=value2) of attributes." />
<cfargument name="outputType" type="string" required="false" default="head"
hint="Indicates to output type for the generated HTML code ('head', 'body', 'inline'). Link tags must be in the HTML head section according to W3C specification. Use the value of inline with caution." />
<cfset var mimeTypeData = resolveMimeTypeAndGetData(arguments.type) />
<cfset var code = "" />
<cfset var key = "" />
<cfif arguments.type EQ "icon">
<cfset code = '<link href="' & computeAssetPath("img", arguments.href) & '"' />
<cfelse>
<cfset code = '<link href="' & arguments.href & '"' />
</cfif>
<cfif arguments.type NEQ "canonical" >
<cfset arguments.attributes = getUtils().parseAttributesIntoStruct(arguments.attributes) />
<cfset StructAppend(arguments.attributes, mimeTypeData, false) />
<cfloop collection="#arguments.attributes#" item="key">
<cfset code = code & ' ' & LCase(key) & '="' & getUtils().escapeHtml(arguments.attributes[key]) & '"' />
</cfloop>
<cfelse>
<cfset code = '<link rel="canonical" href="' & arguments.href & '"' />
</cfif>
<cfset code = code & ' />' & Chr(13) />
<cfif arguments.outputType EQ "inline">
<cfreturn code />
<cfelse>
<cfset appendToHtmlArea(arguments.outputType, code) />
<cfreturn "" />
</cfif>
</cffunction>