]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11442 Fix canonical in docs static website
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 5 Nov 2018 09:54:14 +0000 (10:54 +0100)
committerSonarTech <sonartech@sonarsource.com>
Thu, 8 Nov 2018 19:20:57 +0000 (20:20 +0100)
server/sonar-docs/package.json
server/sonar-docs/src/templates/page.js

index 89467b101b0fc3cec5070df8ccf33a8d41300e1c..b94a477bf88505ea0d6e63af716a5a18c08e9405 100644 (file)
     "singleQuote": true
   },
   "jest": {
-    "moduleFileExtensions": [
-      "js"
-    ],
-    "testPathIgnorePatterns": [
-      "<rootDir>/node_modules",
-      "<rootDir>/.cache"
-    ],
+    "moduleFileExtensions": ["js"],
+    "testPathIgnorePatterns": ["<rootDir>/node_modules", "<rootDir>/.cache"],
     "testRegex": "(/__tests__/.*|\\-test)\\.(ts|tsx|js)$"
   }
 }
index 93d7f2750e0e2343f2a301a763f53941b860ab94..cd29d8180adf2fda7ce0cdf5caacd5a2957562b1 100644 (file)
@@ -25,7 +25,12 @@ import './page.css';
 const version = process.env.GATSBY_DOCS_VERSION || '1.0';
 
 export default class Page extends React.PureComponent {
+  baseUrl = '';
+
   componentDidMount() {
+    if (window) {
+      this.baseUrl = window.location.origin + '/';
+    }
     const collaspables = document.getElementsByClassName('collapse');
     for (let i = 0; i < collaspables.length; i++) {
       collaspables[i].classList.add('close');
@@ -63,7 +68,10 @@ export default class Page extends React.PureComponent {
         <Helmet title={page.frontmatter.title || 'Documentation'}>
           <html lang="en" />
           <link rel="icon" href={`/${version}/favicon.ico`} />
-          <link rel="canonical" href={this.props.location.pathname.replace('latest', version)} />
+          <link
+            rel="canonical"
+            href={this.baseUrl + this.props.location.pathname.replace(version, 'latest')}
+          />
         </Helmet>
         <HeaderList headers={realHeadingsList} />
         <h1>{page.frontmatter.title}</h1>