aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2018-11-05 10:54:14 +0100
committerSonarTech <sonartech@sonarsource.com>2018-11-08 20:20:57 +0100
commit6b837953f06bfd5181580144c955284f168c844e (patch)
tree5daabb1e036d3b9238251a20a7aac5596fd5ba42
parent682ce8e34518e92aea88b368f1d4d1d99a0c6be7 (diff)
downloadsonarqube-6b837953f06bfd5181580144c955284f168c844e.tar.gz
sonarqube-6b837953f06bfd5181580144c955284f168c844e.zip
SONAR-11442 Fix canonical in docs static website
-rw-r--r--server/sonar-docs/package.json9
-rw-r--r--server/sonar-docs/src/templates/page.js10
2 files changed, 11 insertions, 8 deletions
diff --git a/server/sonar-docs/package.json b/server/sonar-docs/package.json
index 89467b101b0..b94a477bf88 100644
--- a/server/sonar-docs/package.json
+++ b/server/sonar-docs/package.json
@@ -41,13 +41,8 @@
"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)$"
}
}
diff --git a/server/sonar-docs/src/templates/page.js b/server/sonar-docs/src/templates/page.js
index 93d7f2750e0..cd29d8180ad 100644
--- a/server/sonar-docs/src/templates/page.js
+++ b/server/sonar-docs/src/templates/page.js
@@ -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>