@@ -6,6 +6,7 @@ const { execSync } = require('child_process');
6
6
const path = require ( 'path' ) ;
7
7
const fs = require ( 'fs' ) ;
8
8
const yaml = require ( 'js-yaml' ) ;
9
+ const { create } = require ( 'domain' ) ;
9
10
10
11
// Calculate the relative paths
11
12
const DOCS_ROOT = process . env . DOCS_ROOT || '.' ;
@@ -50,34 +51,95 @@ function getPathGroups(openapi) {
50
51
return pathGroups ;
51
52
}
52
53
54
+ const CONFIG = {
55
+ apis : [
56
+ {
57
+ name : 'cloud-v2' ,
58
+ menu_name : 'influxdb_cloud' ,
59
+ menu :
60
+ {
61
+ parent : 'INFLUXDB HTTP API' ,
62
+ weight : 0 ,
63
+ } ,
64
+ // Source OpenAPI spec file
65
+ spec_file : path . join ( DOCS_ROOT , '/api-docs/cloud/v2/ref.yml' ) ,
66
+ // Target content directory for generated endpoint spec pages
67
+ // endpoints_dir: path.join(DOCS_ROOT, '/content/influxdb/cloud/api/v2/yaml'),
68
+ // Target content directory for generated .md pages
69
+ pages_dir : path . join ( DOCS_ROOT , '/content/influxdb/cloud/api/v2' ) ,
70
+ } ,
71
+ {
72
+ name : 'oss-v2' ,
73
+ menu_name : 'influxdb_v2' ,
74
+ menu :
75
+ {
76
+ parent : 'INFLUXDB HTTP API' ,
77
+ weight : 0 ,
78
+ } ,
79
+ spec_file : path . join ( DOCS_ROOT , '/api-docs/v2/ref.yml' ) ,
80
+ // Target content directory for generated endpoint spec pages
81
+ // endpoints_dir: path.join(DOCS_ROOT, '/content/influxdb/v2/api/v2/yaml'),
82
+ // Target content directory for generated .md pages
83
+ pages_dir : path . join ( DOCS_ROOT , '/content/influxdb/v2/api/v2' ) ,
84
+ }
85
+ ]
86
+ }
87
+
88
+ function createIndexPage ( spec , api ) {
89
+
90
+ const menu = { ...api . menu , name : spec . info . title } ;
91
+ const pageParams = {
92
+ title : spec . info . title ,
93
+ description : spec . info . description ,
94
+ menu : { } ,
95
+ } ;
96
+ pageParams . menu [ api . menu_name ] = menu ;
97
+
98
+ let frontMatter = JSON . stringify ( pageParams ) ;
99
+ let page = frontMatter . concat ( '\n\n' , spec . info . description , '\n\n' , '{{< children >}}' , '\n\n' ) ;
100
+
101
+ const pagePath = path . join ( api . pages_dir , '_index.md' ) ;
102
+ fs . writeFileSync ( pagePath , page ) ;
103
+ console . log ( `Created: ${ pagePath } ` ) ;
104
+ }
105
+
106
+ function createPathGroupPage ( pathGroup , pathSpec , api ) {
107
+ pathSpec [ 'x-pathGroupTitle' ] = `${ pathGroup } \n${ spec . info . title } ` ;
108
+ pathSpec [ 'x-pathGroup' ] = pathGroup ;
109
+
110
+ const pageParams = {
111
+ type : 'api' ,
112
+ title : pathSpec [ 'x-pathGroupTitle' ] ,
113
+ description : pathSpec . info . description ,
114
+ api : {
115
+ part_of : api . spec_file ,
116
+ spec : JSON . stringify ( pathSpec ) ,
117
+ } ,
118
+ menu : { } ,
119
+ }
120
+
121
+ const menu = {
122
+ parent : spec . info . title ,
123
+ weight : 1 ,
124
+ name : pathGroup
125
+ } ;
126
+
127
+ pageParams . menu [ api . menu_name ] = menu ;
128
+
129
+ let frontMatter = JSON . stringify ( pageParams ) ;
130
+
131
+ const pageName = `${ pathGroup . replaceAll ( '/' , '-' ) . replace ( / ^ - / , '' ) } ` ;
132
+ const pagePath = path . join ( api . pages_dir , `${ pageName } .md` ) ;
133
+ fs . writeFileSync ( pagePath , frontMatter ) ;
134
+ console . log ( `Created: ${ pagePath } ` ) ;
135
+ }
136
+
53
137
function main ( ) {
54
138
/**
55
139
* Configure the product specs to generate markdown files for.
56
140
*/
57
- const config = {
58
- dataDir : path . join ( DOCS_ROOT , '/data/api/influxdb' ) ,
59
- apis : [
60
- {
61
- name : 'cloud-v2' ,
62
- menu : 'influxdb_cloud' ,
63
- // Source OpenAPI spec file
64
- spec_file : path . join ( DOCS_ROOT , '/api-docs/cloud/v2/ref.yml' ) ,
65
- // Target content directory for generated endpoint spec pages
66
- // endpoints_dir: path.join(DOCS_ROOT, '/content/influxdb/cloud/api/v2/yaml'),
67
- // Target content directory for generated .md pages
68
- pages_dir : path . join ( DOCS_ROOT , '/content/influxdb/cloud/api/v2' ) ,
69
- } ,
70
- {
71
- name : 'oss-v2' ,
72
- menu : 'influxdb_v2' ,
73
- spec_file : path . join ( DOCS_ROOT , '/api-docs/v2/ref.yml' ) ,
74
- // Target content directory for generated endpoint spec pages
75
- // endpoints_dir: path.join(DOCS_ROOT, '/content/influxdb/v2/api/v2/yaml'),
76
- // Target content directory for generated .md pages
77
- pages_dir : path . join ( DOCS_ROOT , '/content/influxdb/v2/api/v2' ) ,
78
- }
79
- ]
80
- }
141
+
142
+ let config = CONFIG ;
81
143
82
144
config . apis . forEach ( api => {
83
145
// Execute the getswagger.sh script to fetch and bundle the configured spec.
@@ -93,35 +155,12 @@ function main() {
93
155
fs . mkdirSync ( api . pages_dir , { recursive : true } ) ;
94
156
} ;
95
157
158
+ createIndexPage ( spec , api ) ;
96
159
Object . keys ( pathGroups ) . forEach ( pathGroup => {
97
160
// Deep copy the spec object
98
161
let pathSpec = JSON . parse ( JSON . stringify ( spec ) ) ;
99
162
pathSpec . paths = pathGroups [ pathGroup ] ;
100
- pathSpec [ 'x-pathGroupTitle' ] = `${ pathGroup } \n${ spec . info . title } ` ;
101
- pathSpec [ 'x-pathGroup' ] = pathGroup ;
102
-
103
- const pageParams = {
104
- type : 'api' ,
105
- title : pathSpec [ 'x-pathGroupTitle' ] ,
106
- description : pathSpec . info . description ,
107
- api : {
108
- part_of : api . spec_file ,
109
- spec : JSON . stringify ( pathSpec ) ,
110
- } ,
111
- }
112
- pageParams . menu = { } ;
113
- pageParams . menu [ api . menu ] = {
114
- parent : 'INFLUXDB HTTP API' ,
115
- weight : 1 ,
116
- name : pathGroup
117
- } ;
118
-
119
- let frontMatter = JSON . stringify ( pageParams ) ;
120
-
121
- const pageName = `${ pathGroup . replaceAll ( '/' , '-' ) . replace ( / ^ - / , '' ) } ` ;
122
- const pagePath = path . join ( api . pages_dir , `${ pageName } .md` ) ;
123
- fs . writeFileSync ( pagePath , frontMatter ) ;
124
- console . log ( `Created: ${ pagePath } ` ) ;
163
+ createPathGroupPage ( pathGroup , pathSpec , api ) ;
125
164
} ) ;
126
165
} ) ;
127
166
}
0 commit comments