@@ -36,27 +36,30 @@ while getopts "hc" opt; do
36
36
done
37
37
38
38
function generateHtml {
39
- specPath=" $1 "
40
- product =" $2 "
41
- productName=" $3 "
42
- api=" $4 "
43
- configPath=" $5 "
44
- isDefault=$6
39
+ local specPath=" $1 "
40
+ local productVersion =" $2 "
41
+ local productName=" $3 "
42
+ local api=" $4 "
43
+ local configPath=" $5 "
44
+ local isDefault=$6
45
45
46
46
# Use the product name to define the menu for the Hugo template
47
- menu=" influxdb_$( echo $product | sed ' s/\./_/g;s/-/_/g;' ) "
47
+ local menu=" $( echo $productVersion | sed ' s/\./_/g;s/-/_/g;s/\//_/g;' ) "
48
+ # Short version name (for old aliases)
49
+ # Everything after the last slash
50
+ local versionDir=$( echo $productVersion | sed ' s/.*\///g;' )
48
51
# Extract the API name--for example, "management" from "management@v2".
49
- apiName=$( echo $api | sed ' s/@.*//g;' )
52
+ local apiName=$( echo $api | sed ' s/@.*//g;' )
50
53
# Extract the API version--for example, "v0" from "management@v0".
51
- version =$( echo $api | sed ' s/.*@//g;' )
54
+ local apiVersion =$( echo $api | sed ' s/.*@//g;' )
52
55
# Use the title and summary defined in the product API's info.yml file.
53
- title=$( yq ' .title' $product /$apiName /content/info.yml)
54
- menuTitle=$( yq ' .x-influxdata-short-title' $product /$apiName /content/info.yml)
55
- description=$( yq ' .summary' $product /$apiName /content/info.yml)
56
+ local title=$( yq ' .title' $productVersion /$apiName /content/info.yml)
57
+ local menuTitle=$( yq ' .x-influxdata-short-title' $productVersion /$apiName /content/info.yml)
58
+ local description=$( yq ' .summary' $productVersion /$apiName /content/info.yml)
56
59
# Define the file name for the Redoc HTML output.
57
- specbundle=redoc-static_index.html
60
+ local specbundle=redoc-static_index.html
58
61
# Define the temporary file for the Hugo template and Redoc HTML.
59
- tmpfile=" ${product } -${api} _index.tmp"
62
+ local tmpfile=" ${productVersion } -${api} _index.tmp"
60
63
61
64
echo " Bundling $specPath "
62
65
@@ -75,7 +78,7 @@ function generateHtml {
75
78
--options.noAutoAuth \
76
79
--output=$specbundle \
77
80
--templateOptions.description=$description \
78
- --templateOptions.product=" $product " \
81
+ --templateOptions.product=" $productVersion " \
79
82
--templateOptions.productName=" $productName "
80
83
81
84
if [[ $apiName == " v1-compatibility" ]]; then
@@ -90,10 +93,10 @@ menu:
90
93
identifier: api-reference-$apiName
91
94
weight: 304
92
95
aliases:
93
- - /influxdb/$product /api/v1/
96
+ - /influxdb/$versionDir /api/v1/
94
97
---
95
98
"
96
- elif [[ $version == " 0" ]]; then
99
+ elif [[ $apiVersion == " 0" ]]; then
97
100
echo $productName $apiName
98
101
frontmatter=" ---
99
102
title: $title
@@ -119,7 +122,7 @@ menu:
119
122
identifier: api-reference-$apiName
120
123
weight: 102
121
124
aliases:
122
- - /influxdb/$product /api/
125
+ - /influxdb/$versionDir /api/
123
126
---
124
127
"
125
128
else
@@ -152,68 +155,74 @@ weight: 102
152
155
rm -f $specbundle
153
156
# Create the directory and move the file.
154
157
if [ ! -z " $apiName " ]; then
155
- mkdir -p ../content/influxdb/ $product /api/$apiName
156
- mv $tmpfile ../content/influxdb/ $product /api/$apiName /_index.html
158
+ mkdir -p ../content/$productVersion /api/$apiName
159
+ mv $tmpfile ../content/$productVersion /api/$apiName /_index.html
157
160
else
158
- mkdir -p ../content/influxdb/ $product /api
159
- mv $tmpfile ../content/influxdb/ $product /api/_index.html
161
+ mkdir -p ../content/$productVersion /api
162
+ mv $tmpfile ../content/$productVersion /api/_index.html
160
163
fi
161
164
}
162
165
163
166
# Use a combination of directory names and configuration files to build the API documentation.
164
167
# Each directory represents a product, and each product directory contains a configuration file that defines APIs and their spec file locations.
165
168
function build {
166
- # Get the list of products from directory names
167
- products=" $( ls -d -- * / | grep -v ' node_modules' | grep -v ' openapi' ) "
168
-
169
- for product in $products ; do
170
- # Trim the trailing slash off the directory name
171
- product=" ${product%/ } "
172
- # Get the product API configuration file.
173
- configPath=" $product /.config.yml"
174
- if [ ! -f $configPath ]; then
175
- configPath=" .config.yml"
176
- fi
177
- echo " Checking product config $configPath "
178
- # Get the product name from the configuration.
179
- productName=$( yq e ' .x-influxdata-product-name' $configPath )
180
- if [[ -z " $productName " ]]; then
181
- productName=InfluxDB
182
- fi
183
- # Get an array of product API names (keys) from the configuration file
184
- apis=$( yq e ' .apis | keys | .[]' $configPath )
185
- # Read each element of the apis array
186
- while IFS= read -r api; do
187
- # Get the spec file path from the configuration.
188
- specRootPath=$( yq e " .apis | .$api | .root" $configPath )
189
- # Check that the YAML spec file exists.
190
- specPath=" $product /$specRootPath "
191
- echo " Checking for spec $specPath "
192
- if [ -d " $specPath " ] || [ ! -f " $specPath " ]; then
193
- echo " OpenAPI spec $specPath doesn't exist."
169
+ local versions
170
+ versions=" $( ls -d -- * /* | grep -v ' node_modules' | grep -v ' openapi' ) "
171
+ for version in $versions ; do
172
+ # Trim the trailing slash off the directory name
173
+ local version=" ${version%/ } "
174
+ # Get the version API configuration file.
175
+ local configPath=" $version /.config.yml"
176
+ if [ ! -f " $configPath " ]; then
177
+ configPath=" .config.yml"
194
178
fi
195
- # Get default status from the configuration.
196
- isDefault=false
197
- defaultStatus=$( yq e " .apis | .$api | .x-influxdata-default" $configPath )
198
- if [[ $defaultStatus == " true" ]]; then
199
- isDefault=true
179
+ echo " Using config $configPath "
180
+ # Get the product name from the configuration.
181
+ local versionName
182
+ versionName=$( yq e ' .x-influxdata-product-name' " $configPath " )
183
+ if [[ -z " $versionName " ]]; then
184
+ versionName=InfluxDB
200
185
fi
186
+ # Get an array of API names (keys) from the configuration file
187
+ local apis
188
+ apis=$( yq e ' .apis | keys | .[]' " $configPath " )
189
+ # Read each element of the apis array
190
+ while IFS= read -r api; do
191
+ echo " ======Building $version $api ======"
192
+ # Get the spec file path from the configuration.
193
+ local specRootPath
194
+ specRootPath=$( yq e " .apis | .$api | .root" " $configPath " )
195
+ # Check that the YAML spec file exists.
196
+ local specPath
197
+ specPath=" $version /$specRootPath "
198
+ if [ -d " $specPath " ] || [ ! -f " $specPath " ]; then
199
+ echo " OpenAPI spec $specPath doesn't exist."
200
+ fi
201
+ # Get default status from the configuration.
202
+ local isDefault=false
203
+ local defaultStatus
204
+ defaultStatus=$( yq e " .apis | .$api | .x-influxdata-default" " $configPath " )
205
+ if [[ $defaultStatus == " true" ]]; then
206
+ isDefault=true
207
+ fi
201
208
202
- # If the spec file differs from master, regenerate the HTML.
203
- update=0
204
- if [[ $generate_changed == 0 ]]; then
205
- diff=$( git diff --name-status master -- ${specPath} )
206
- if [[ -z " $diff " ]]; then
207
- update=1
209
+ # If the spec file differs from master, regenerate the HTML.
210
+ local update=0
211
+ if [[ $generate_changed == 0 ]]; then
212
+ local diff
213
+ diff=$( git diff --name-status master -- " ${specPath} " )
214
+ if [[ -z " $diff " ]]; then
215
+ update=1
216
+ fi
208
217
fi
209
- fi
210
218
211
- if [[ $update -eq 0 ]]; then
212
- echo " Regenerating $product $api "
213
- generateHtml " $specPath " " $product " " $productName " " $api " " $configPath " $isDefault
214
- fi
215
- done <<< " $apis"
216
- done
219
+ if [[ $update -eq 0 ]]; then
220
+ echo " Regenerating $version $api "
221
+ generateHtml " $specPath " " $version " " $versionName " " $api " " $configPath " " $isDefault "
222
+ fi
223
+ echo " ========Done with $version $api ========"
224
+ done <<< " $apis"
225
+ done
217
226
}
218
227
219
228
build
0 commit comments