From b949a4a9fcf9dd3a6f4cca6f6e3ace950e30fd44 Mon Sep 17 00:00:00 2001 From: adaines Date: Tue, 25 Nov 2025 13:27:42 -0500 Subject: [PATCH] Fix canonical URLs to use direct page paths for SEO --- .../SDKDocGeneratorLib/Writers/BaseWriter.cs | 7 ++-- .../output-files/resources/parentloader.js | 38 +++++++------------ 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/docgenerator/SDKDocGeneratorLib/Writers/BaseWriter.cs b/docgenerator/SDKDocGeneratorLib/Writers/BaseWriter.cs index 78871cfdd605..047886223cb3 100644 --- a/docgenerator/SDKDocGeneratorLib/Writers/BaseWriter.cs +++ b/docgenerator/SDKDocGeneratorLib/Writers/BaseWriter.cs @@ -132,9 +132,10 @@ public void Write() writer.WriteLine("", GetTitle()); writer.WriteLine("{0} | AWS SDK for .NET Version 4", GetTitle()); writer.WriteLine(""); - writer.WriteLine("", - FilenameGenerator.Escape(this.GenerateFilename()), - FilenameGenerator.Escape(this.GetTOCID())); + writer.WriteLine("", FilenameGenerator.Escape(this.GetTOCID())); + writer.WriteLine("", + FilenameGenerator.Escape(this.GenerateFilepath()), + FilenameGenerator.Escape(this.GenerateFilename())); writer.WriteLine(""); diff --git a/docgenerator/SDKDocGeneratorLib/output-files/resources/parentloader.js b/docgenerator/SDKDocGeneratorLib/output-files/resources/parentloader.js index bba04b241980..c88da1d25e34 100644 --- a/docgenerator/SDKDocGeneratorLib/output-files/resources/parentloader.js +++ b/docgenerator/SDKDocGeneratorLib/output-files/resources/parentloader.js @@ -31,31 +31,21 @@ } } else { - //This content page is not in the expected frameset which contains the TOC so - //reload the parent frame and cause it to reload this page in the frame. The - //canonical link element contains the link to reload the entire parent frameset - //and load this current content page. - var pageLink = jQuery("link[rel='canonical']").attr('href'); - if (pageLink !== '') { - //Canonical links look like this: http://docs.aws.amazon.com/sdkfornet/v4/apidocs/index.html?page=PAGE.html&tocid=TOCID - //Attempt to find where the relative path starts after the hostname. - var seekFrom = 0; - var protocolEndIndex = pageLink.indexOf('://'); - if (protocolEndIndex != -1) { - seekFrom = protocolEndIndex + 3; - } + //This content page is not in the expected frameset which contains the TOC so + //reload the parent frame and cause it to reload this page in the frame. + //Read the tocid from the meta tag and build the frameset URL. + var tocid = jQuery("meta[name='aws-tocid']").attr('content'); + var pathname = window.location.pathname; + var itemsIndex = pathname.indexOf('/items/'); - //Look for the start of the relative path. - var relPathIndex = pageLink.indexOf('/', seekFrom); - if (relPathIndex != -1) { - //Reload the parent frameset and this content page. Note the address bar URL will - //look like the canonical link in the address bar. The inFrame part of this script - //will run on release to replace the address bar URL with the actual friendly content - //frame page URL. - window.location.href = pageLink.substring(relPathIndex); - } - //Else do nothing because the link doesn't appear to be in a normal URL format where the - //hostname ends with a / starting the relative URL path. + if (tocid && itemsIndex !== -1) { + //Build the frameset URL from the current path + var basePath = pathname.substring(0, itemsIndex); + var filename = pathname.substring(pathname.lastIndexOf('/') + 1); + //Reload the parent frameset and this content page. The inFrame part of this script + //will run on reload to replace the address bar URL with the actual friendly content + //frame page URL. + window.location.href = basePath + '/index.html?page=' + filename + '&tocid=' + tocid; } } })(); \ No newline at end of file