aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/config
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-07-13 12:27:02 +0200
committerSonarTech <sonartech@sonarsource.com>2018-07-25 20:21:20 +0200
commitb998b44aafeff3726122bbc491e2c84aed284b61 (patch)
treefbc8aea8d272107b7aeeec6b89e6cee1eac93ef6 /server/sonar-web/config
parent4423587a87475044fb3eea1229eca5f52177db95 (diff)
downloadsonarqube-b998b44aafeff3726122bbc491e2c84aed284b61.tar.gz
sonarqube-b998b44aafeff3726122bbc491e2c84aed284b61.zip
SONAR-11013 Add search capabilities to the embedded documentation (#513)
Diffstat (limited to 'server/sonar-web/config')
-rw-r--r--server/sonar-web/config/documentation-loader/fetch-matter.js45
-rw-r--r--server/sonar-web/config/documentation-loader/index.js26
-rw-r--r--server/sonar-web/config/documentation-loader/parse-directory.js24
3 files changed, 22 insertions, 73 deletions
diff --git a/server/sonar-web/config/documentation-loader/fetch-matter.js b/server/sonar-web/config/documentation-loader/fetch-matter.js
deleted file mode 100644
index 806332edb2a..00000000000
--- a/server/sonar-web/config/documentation-loader/fetch-matter.js
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-const fs = require('fs');
-const path = require('path');
-const { getFrontMatter } = require('../../src/main/js/helpers/markdown');
-
-const compare = (a, b) => {
- if (a.order === b.order) return a.title.localeCompare(b.title);
- if (a.order === -1) return 1;
- if (b.order === -1) return -1;
- return a.order - b.order;
-};
-
-module.exports = (root, files) => {
- return files
- .map(file => {
- const content = fs.readFileSync(root + '/' + file, 'utf8');
- const headerData = getFrontMatter(content);
- return {
- name: path.basename(file).slice(0, -3),
- relativeName: file.slice(0, -3),
- title: headerData.title || file,
- order: headerData.order || -1,
- scope: headerData.scope && headerData.scope.toLowerCase()
- };
- })
- .sort(compare);
-};
diff --git a/server/sonar-web/config/documentation-loader/index.js b/server/sonar-web/config/documentation-loader/index.js
index d25477bedd9..bf184f6341e 100644
--- a/server/sonar-web/config/documentation-loader/index.js
+++ b/server/sonar-web/config/documentation-loader/index.js
@@ -17,9 +17,9 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+const fs = require('fs');
const path = require('path');
-const parseDirectory = require('./parse-directory');
-const fetchMatter = require('./fetch-matter');
+const glob = require('glob-promise');
module.exports = function(source) {
this.cacheable();
@@ -31,9 +31,27 @@ module.exports = function(source) {
const root = path.resolve(path.dirname(this.resourcePath), config.root);
this.addContextDependency(root);
- parseDirectory(root)
- .then(files => fetchMatter(root, files))
+ glob(root + '/**/*.md')
+ .then(files => files.map(file => file.substr(root.length + 1)))
+ .then(files =>
+ files.map(file => ({
+ path: file.slice(0, -3),
+ content: handleIncludes(fs.readFileSync(root + '/' + file, 'utf8'), root)
+ }))
+ )
.then(result => `module.exports = ${JSON.stringify(result)};`)
.then(success)
.catch(failure);
};
+
+/**
+ * @param {string} content
+ * @param {string} root
+ * @returns {string}
+ */
+function handleIncludes(content, root) {
+ return content.replace(/@include (.+)/, (match, p) => {
+ const filePath = path.join(root, '..', `${p}.md`);
+ return fs.readFileSync(filePath, 'utf8');
+ });
+}
diff --git a/server/sonar-web/config/documentation-loader/parse-directory.js b/server/sonar-web/config/documentation-loader/parse-directory.js
deleted file mode 100644
index 35b37040d72..00000000000
--- a/server/sonar-web/config/documentation-loader/parse-directory.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-const glob = require('glob-promise');
-
-module.exports = root => {
- return glob(root + '/**/*.md').then(files => files.map(file => file.substr(root.length + 1)));
-};