Skip to content

Commit 4ecef4b

Browse files
authored
ui: prevent same string docHelp override (#5014)
Prevent same string docHelp suffix override. List all existing docHelp suffixes in the config file during the build process. Updated apache/cloudstack-documentation#199 Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 493d6a0 commit 4ecef4b

5 files changed

Lines changed: 89 additions & 4 deletions

File tree

ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
"url": "https://github.com/apache/cloudstack/issues"
2525
},
2626
"scripts": {
27+
"prebuild": "./prebuild.sh",
2728
"start": "vue-cli-service lint --no-fix && vue-cli-service serve",
2829
"serve": "vue-cli-service lint --no-fix && vue-cli-service serve",
2930
"build": "vue-cli-service build",
31+
"postbuild": "./postbuild.sh",
3032
"lint": "vue-cli-service lint",
3133
"i18n:report": "vue-cli-service i18n:report --src './src/**/*.?(js|vue)' --locales './src/locales/**/*.json'",
3234
"test:unit": "vue-cli-service test:unit"

ui/postbuild.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
DIR=$(dirname $0)
20+
configFile="$DIR/public/config.json"
21+
tmpFile="$DIR/public/config.json.tmp"
22+
echo "Post-build: removing all docHelp suffixes in ${configFile}"
23+
24+
node > ${tmpFile} <<EOF
25+
// Read config
26+
var data = require('${configFile}');
27+
28+
// Clear docHelpMappings
29+
data.docHelpMappings = {};
30+
31+
// Output config
32+
console.log(JSON.stringify(data, null, 2));
33+
34+
EOF
35+
36+
mv ${tmpFile} ${configFile}

ui/prebuild.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
DIR=$(dirname $0)
20+
configFile="$DIR/public/config.json"
21+
tmpFile="$DIR/public/config.json.tmp"
22+
echo "Pre-build: list all docHelp suffixes in ${configFile}"
23+
for m in $(grep "docHelp: '" -R ./src | sed "s/^.*: '//g" | sed "s/',//g" | sort | uniq); do
24+
docHelpMappings+="${m},"
25+
done;
26+
27+
node > ${tmpFile} <<EOF
28+
// Read config
29+
var data = require('${configFile}');
30+
31+
// Add docHelpMappings
32+
var suffixes = '${docHelpMappings}';
33+
suffixes = suffixes.split(',');
34+
var mappings = {}
35+
for (const suffix of suffixes) {
36+
if (suffix) {
37+
mappings[suffix] = suffix;
38+
}
39+
}
40+
data.docHelpMappings = mappings;
41+
42+
// Output config
43+
console.log(JSON.stringify(data, null, 2));
44+
45+
EOF
46+
47+
mv ${tmpFile} ${configFile}

ui/public/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"logo": "assets/logo.svg",
77
"banner": "assets/banner.svg",
88
"error": {
9-
"404": "assets/404.png",
109
"403": "assets/403.png",
10+
"404": "assets/404.png",
1111
"500": "assets/500.png"
1212
},
1313
"theme": {
@@ -46,7 +46,7 @@
4646
"jp": "label.japanese.keyboard",
4747
"sc": "label.simplified.chinese.keyboard"
4848
},
49-
"docHelpMappings": {},
5049
"plugins": [],
51-
"basicZoneEnabled": true
50+
"basicZoneEnabled": true,
51+
"docHelpMappings": {}
5252
}

ui/src/utils/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const configUtilPlugin = {
175175
if (docHelp && docHelpMappings &&
176176
docHelpMappings.constructor === Object && Object.keys(docHelpMappings).length > 0) {
177177
for (var key in docHelpMappings) {
178-
if (docHelp.includes(key)) {
178+
if (docHelp.includes(key) && docHelp !== docHelpMappings[key]) {
179179
docHelp = docHelp.replace(key, docHelpMappings[key])
180180
break
181181
}

0 commit comments

Comments
 (0)