forked from influxdata/docs-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace-shortcodes.cjs
More file actions
37 lines (32 loc) · 1.08 KB
/
replace-shortcodes.cjs
File metadata and controls
37 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module.exports = ReplaceShortcodes;
function replaceDocsUrl(field) {
if(!field) { return }
/** Regex to match the URL "shortcode" {{% INFLUXDB_DOCS_URL %}}.
* [^]* matches line breaks. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#using_regular_expression_on_multiple_lines
*/
const shortcode = /\{\{%([^]|\s)*?INFLUXDB_DOCS_URL([^]|\s)*?%\}\}/g
let replacement = `/influxdb/${process.env.INFLUXDB_PRODUCT}`;
field = field.replaceAll(shortcode, replacement)
.replaceAll('https://docs.influxdata.com/influxdb/', '/influxdb/');
if(process.env.INFLUXDB_PRODUCT === 'cloud-iox') {
field = field.replaceAll('/influxdb/cloud/', `${replacement}/`);
}
return field;
}
/** @type {import('@redocly/openapi-cli').OasDecorator} */
function docsUrl() {
return {
any: {
leave(node, ctx) {
if(node.description && typeof(node.description) === 'string') {
node.description = replaceDocsUrl(node.description);
}
},
},
}
}
function ReplaceShortcodes() {
return {
docsUrl,
};
}