Canonical URL

Post here questions and problems related to editing and publishing DITA content.
scotmarvin
Posts: 18
Joined: Thu Aug 27, 2009 5:09 pm

Canonical URL

Post by scotmarvin »

Hi, I'm trying to figure out how to generate a canonical URL in the webhelp metadata. Is there a way to have Oxygen's webhelp generate such additional metadata?

Thanks,

-Scot
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Canonical URL

Post by sorin_ristache »

Hi,

You can add XHTML metadata tags in the Webhelp output by adding an XHTML <meta> element in the template:

Code: Select all

<xsl:template name="jsAndCSS">
in the stylesheet:

Code: Select all

[Oxygen-install-dir]\frameworks\dita\DITA-OT\plugins\com.oxygenxml.webhelp\xsl\dita\desktop\common.xsl
There is already a <meta> element that is added there by default so you can just add your <meta> element after that:

Code: Select all

<meta xmlns="http://www.w3.org/1999/xhtml" http-equiv="Content-Type" content="text/html; charset=utf-8"><xsl:comment/></meta>

Regards,
Sorin
scotmarvin
Posts: 18
Joined: Thu Aug 27, 2009 5:09 pm

Re: Canonical URL

Post by scotmarvin »

Thanks, Sorin. I was able to generate the path, but then it hit: I'm not all that smart. How the heck do I get the filename of the XML file (or its ID--which is the same in our repository) and then append ".html"?

Any ideas? My XSL skills have atrophied apparently.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Canonical URL

Post by sorin_ristache »

Do you have to read the filename of the XML file in the XSLT code? If yes how or where do you read it?

Or maybe you receive it from the process that calls the XSLT stylesheet? In this case you can pass it as a parameter that is received in XSLT with a line like:

Code: Select all

<xsl:param name="XML-file-path"/>
You append the file extension with an element like:

Code: Select all

<xsl:value-of select="concat($XML-file-path, '.html')"/>

Regards,
Sorin
scotmarvin
Posts: 18
Joined: Thu Aug 27, 2009 5:09 pm

Re: Canonical URL

Post by scotmarvin »

Actually, I'm not sure what we have to do. Currently, we're not passing it along. I've read that this is the only way to get the information I need. When I try a general XPATH-based solution, like base-uri, I only get the name of the XSL file which, in this case, is common.xsl.

Your solution about getting the param and appending the ".html" onto it seems like it should work (currently, it generates a "href='.html'". So how the heck do I pass along each XML filename parameter? I mean, the processor is working on each file in the ditamap. It seems like there's some way to address this. I just don't know how.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Canonical URL

Post by sorin_ristache »

Hi Scott,

You should start from document-uri(/). If you need only the file name, just extract it from the URI of the XML document returned by this function call.


Regards,
Sorin
scotmarvin
Posts: 18
Joined: Thu Aug 27, 2009 5:09 pm

Re: Canonical URL

Post by scotmarvin »

Just in case anyone else hasn't figured this out, here's what my lovely wife came up with and it works great (all edits in /frameworks/dita/DITA-OT/plugins/comoxygenxml.webhelp/xsl/dita/desktop/common.xsl):

1. At the top, with the other params, add the following params:

Code: Select all

<xsl:param name="pathuri" select="tokenize(document-uri(/), 'oxygen_dita_temp')[last()]"/>
<xsl:param name="filename" select="tokenize($pathuri, '\.')[1]"/>
<xsl:param name="fileuri" select="concat($filename, '.html')"/>
2. In the jsAndCSS template, add the following:

Code: Select all

<link rel="canonical">
<xsl:attribute name="href">http://www.eucalyptus.com/docs/eucalyptus/latest<xsl:value-of select="$fileuri"/></xsl:attribute>
</link>
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Canonical URL

Post by sorin_ristache »

Hi Scot,

Thank you for letting us know.

The variable fileuri will hold a file name, not a URI. Anyway it is good that you could create the URI that you need in the <link rel="canonical"> element.


Regards,
Sorin
jomjohn
Posts: 1
Joined: Tue Jan 08, 2019 1:35 am

Re: Canonical URL

Post by jomjohn »

I am attempting to add a <link rel="canonical"> element to the latest webhelp responsive (com.oxygenxml.webhelp.responsive) output.

The template <xsl:template name="jsAndCSS"> does not exist as it did with the classic webhelp.

Can you please give me direction on the appropriate template to override?

thanks,
-Josh
Costin
Posts: 829
Joined: Mon Dec 05, 2011 6:04 pm

Re: Canonical URL

Post by Costin »

Hello,

Please note that com.oxygenxml.webhelp.classic and com.oxygenxml.webhelp.responsive are two separate plugins with totally different templates, so you could not interchange templates from one plugin to the other.

If you need to customize the WebHelp Responsive output, by inserting custom content (like references to additional JavaScript, CSS, and other types of resources), you could use XML files that contain HTML fragments that contain the references to that content.
More details on using HTML fragments to customize the WebHelp Responsive output available in the "How to Insert HTML Content in WebHelp Responsive Output" section from the User-Guide.

Regards,
Costin
Costin Sandoi
oXygen XML Editor and Author Support
syed
Posts: 76
Joined: Tue Nov 14, 2017 8:34 pm

Re: Canonical URL

Post by syed »

Hi,
Are there instructions to add the canonical link for the Webhelp Responsive output? I am using v25. In my case, the href value has to be supplied by the teams because each team will have a different URL. Maybe like the sitemap.base.url parameter, there can be a canonical.url parameter?

Syed
beniamin_savu
Posts: 31
Joined: Fri Jan 22, 2021 11:05 am

Re: Canonical URL

Post by beniamin_savu »

Hi,

Unfortunately we do not have a way to add canonical link for the WebHelp Responsive output out of the box. We added an issue (WH-3257) in our internal issue tracker to be further analyzed by our development team. We will let you know when it will be implemented.

However, WebHelp can be customized using XSLT Extension Points. We think it may be possible to achieve this functionality by creating a custom XSLT that adds a link with the canonical URL.

Best regards,
Beniamin Savu
Oxygen WebHelp Team
http://www.oxygenxml.com
Post Reply