Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLHelperProperty addLink() issue with type=canonical #83

Open
mfran opened this issue Jul 9, 2012 · 0 comments
Open

HTMLHelperProperty addLink() issue with type=canonical #83

mfran opened this issue Jul 9, 2012 · 0 comments

Comments

@mfran
Copy link

mfran commented Jul 9, 2012

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." />

&lt;cfset var mimeTypeData = resolveMimeTypeAndGetData(arguments.type) /&gt;
&lt;cfset var code = "" /&gt;
&lt;cfset var key = "" /&gt;

&lt;cfif arguments.type EQ "icon"&gt;
    &lt;cfset code = '&lt;link href="' & computeAssetPath("img", arguments.href) & '"' /&gt;
&lt;cfelse&gt;
    &lt;cfset code = '&lt;link href="' & arguments.href & '"' /&gt;
&lt;/cfif&gt;

&lt;cfif arguments.type NEQ "canonical" &gt;
    &lt;cfset arguments.attributes = getUtils().parseAttributesIntoStruct(arguments.attributes) /&gt;
    &lt;cfset StructAppend(arguments.attributes, mimeTypeData, false) /&gt;
    &lt;cfloop collection="#arguments.attributes#" item="key"&gt;
        &lt;cfset code = code & ' ' & LCase(key) & '="' & getUtils().escapeHtml(arguments.attributes[key]) & '"' /&gt;
    &lt;/cfloop&gt;
&lt;cfelse&gt;
    &lt;cfset code = '&lt;link rel="canonical" href="' & arguments.href & '"' /&gt;
&lt;/cfif&gt;

&lt;cfset code = code & ' /&gt;' & Chr(13) /&gt;

&lt;cfif arguments.outputType EQ "inline"&gt;
    &lt;cfreturn code /&gt;
&lt;cfelse&gt;
    &lt;cfset appendToHtmlArea(arguments.outputType, code) /&gt;
    &lt;cfreturn "" /&gt;
&lt;/cfif&gt;

</cffunction>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant