Skip to content

Commit b949a4a

Browse files
committed
Fix canonical URLs to use direct page paths for SEO
1 parent f8af87d commit b949a4a

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

docgenerator/SDKDocGeneratorLib/Writers/BaseWriter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ public void Write()
132132
writer.WriteLine("<meta name=\"description\" content=\"{0}\">", GetTitle());
133133
writer.WriteLine("<title>{0} | AWS SDK for .NET Version 4</title>", GetTitle());
134134
writer.WriteLine("<script type=\"text/javascript\" src=\"/assets/js/awsdocs-boot.js\"></script>");
135-
writer.WriteLine("<link rel=\"canonical\" href=\"https://docs.aws.amazon.com/sdkfornet/v4/apidocs/index.html?page={0}&tocid={1}\"/>",
136-
FilenameGenerator.Escape(this.GenerateFilename()),
137-
FilenameGenerator.Escape(this.GetTOCID()));
135+
writer.WriteLine("<meta name=\"aws-tocid\" content=\"{0}\"/>", FilenameGenerator.Escape(this.GetTOCID()));
136+
writer.WriteLine("<link rel=\"canonical\" href=\"https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/{0}/{1}\"/>",
137+
FilenameGenerator.Escape(this.GenerateFilepath()),
138+
FilenameGenerator.Escape(this.GenerateFilename()));
138139

139140
writer.WriteLine("</head>");
140141

docgenerator/SDKDocGeneratorLib/output-files/resources/parentloader.js

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,21 @@
3131
}
3232
}
3333
else {
34-
//This content page is not in the expected frameset which contains the TOC so
35-
//reload the parent frame and cause it to reload this page in the frame. The
36-
//canonical link element contains the link to reload the entire parent frameset
37-
//and load this current content page.
38-
var pageLink = jQuery("link[rel='canonical']").attr('href');
39-
if (pageLink !== '') {
40-
//Canonical links look like this: http://docs.aws.amazon.com/sdkfornet/v4/apidocs/index.html?page=PAGE.html&tocid=TOCID
41-
//Attempt to find where the relative path starts after the hostname.
42-
var seekFrom = 0;
43-
var protocolEndIndex = pageLink.indexOf('://');
44-
if (protocolEndIndex != -1) {
45-
seekFrom = protocolEndIndex + 3;
46-
}
34+
//This content page is not in the expected frameset which contains the TOC so
35+
//reload the parent frame and cause it to reload this page in the frame.
36+
//Read the tocid from the meta tag and build the frameset URL.
37+
var tocid = jQuery("meta[name='aws-tocid']").attr('content');
38+
var pathname = window.location.pathname;
39+
var itemsIndex = pathname.indexOf('/items/');
4740

48-
//Look for the start of the relative path.
49-
var relPathIndex = pageLink.indexOf('/', seekFrom);
50-
if (relPathIndex != -1) {
51-
//Reload the parent frameset and this content page. Note the address bar URL will
52-
//look like the canonical link in the address bar. The inFrame part of this script
53-
//will run on release to replace the address bar URL with the actual friendly content
54-
//frame page URL.
55-
window.location.href = pageLink.substring(relPathIndex);
56-
}
57-
//Else do nothing because the link doesn't appear to be in a normal URL format where the
58-
//hostname ends with a / starting the relative URL path.
41+
if (tocid && itemsIndex !== -1) {
42+
//Build the frameset URL from the current path
43+
var basePath = pathname.substring(0, itemsIndex);
44+
var filename = pathname.substring(pathname.lastIndexOf('/') + 1);
45+
//Reload the parent frameset and this content page. The inFrame part of this script
46+
//will run on reload to replace the address bar URL with the actual friendly content
47+
//frame page URL.
48+
window.location.href = basePath + '/index.html?page=' + filename + '&tocid=' + tocid;
5949
}
6050
}
6151
})();

0 commit comments

Comments
 (0)