Skip to content

Commit

Permalink
Support doc page redirects for ALL services (#2879)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan343 committed Mar 15, 2023
1 parent 82aee34 commit 5d22dbb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions docs/source/_static/js/custom.js
Expand Up @@ -15,9 +15,10 @@ limitations under the License.
*/

// Checks if an html doc name matches a service class name.
function isValidServiceName(docName, serviceClassName) {
const new_docName = docName.replaceAll('-', '').toLowerCase();
return new_docName === serviceClassName;
function isValidServiceName(serviceClassName) {
const pageTitle = document.getElementsByTagName('h1')[0];
const newDocName = pageTitle.getElementsByTagName('a')[0].innerHTML;
return newDocName.toLowerCase() === serviceClassName;
}
// Checks if all elements of the split fragment are valid.
// Fragment items should only contain alphanumerics, hyphens, & underscores.
Expand All @@ -44,7 +45,7 @@ function isValidFragment(splitFragment) {
const serviceDocName = currentPath[currentPath.length - 1].replace('.html', '');
const splitFragment = fragment.split('.');
splitFragment[0] = splitFragment[0].toLowerCase();
if (isValidFragment(splitFragment) && isValidServiceName(serviceDocName, splitFragment[0])) {
if (isValidFragment(splitFragment) && isValidServiceName(splitFragment[0])) {
// Replace class name with doc name
splitFragment[0] = serviceDocName;
splitFragment[1] = splitFragment[1].toLowerCase();
Expand Down

0 comments on commit 5d22dbb

Please sign in to comment.