@@ -109,6 +109,22 @@ const showErrorMsg = failedTest => {
109
109
console . log ( stderr ) ;
110
110
} ;
111
111
112
+ const createApiIndexModules = version => {
113
+ const dir = path . join ( __dirname , ".." , "data" , "api" , version ) ;
114
+ const modules = fs . readdirSync ( dir ) . filter ( file => file !== "toc_tree.json" ) ;
115
+ const paths = modules . reduce ( ( acc , file ) => {
116
+ const json = JSON . parse ( fs . readFileSync ( path . join ( dir , file ) ) ) ;
117
+ const keys = Object . keys ( json ) ;
118
+
119
+ const paths = keys . map ( modulePath => path . join ( version , "api" , modulePath ) ) ;
120
+
121
+ return acc . concat ( paths ) ;
122
+ } , [ ] ) ;
123
+ return paths ;
124
+ } ;
125
+
126
+ const apiIndexModules = createApiIndexModules ( "latest" )
127
+
112
128
const testFile = ( pageMap , test ) => {
113
129
const filepath = test . filepath ;
114
130
@@ -161,11 +177,30 @@ const testFile = (pageMap, test) => {
161
177
}
162
178
}
163
179
180
+ if ( resolved . startsWith ( "/pages/docs/manual/latest/api" ) ) {
181
+ const pathToModule = resolved . replace ( "/pages/docs/manual/" , "" ) ;
182
+ const pathExists = apiIndexModules . includes ( pathToModule ) ;
183
+
184
+ if ( pathExists ) {
185
+ results . push ( {
186
+ status : "ok" ,
187
+ link
188
+ } ) ;
189
+ } else {
190
+ const { line, column } = link . position . start ;
191
+ const stderr = `${ filepath } : Unknown href '${ url } ' in line ${ line } :${ column } ` ;
192
+ results . push ( {
193
+ status : "failed" ,
194
+ filepath,
195
+ stderr,
196
+ link
197
+ } ) ;
198
+ }
199
+ return ;
200
+ }
201
+
164
202
// If there's no page stated the relative link
165
203
if ( ! pageMap [ resolved ] ) {
166
- if ( url . includes ( "/docs/manual/latest/api" ) || url . includes ( "api" ) ) {
167
- return ;
168
- }
169
204
const { line, column } = link . position . start ;
170
205
const stderr = `${ filepath } : Unknown href '${ url } ' in line ${ line } :${ column } ` ;
171
206
results . push ( {
@@ -225,8 +260,6 @@ const main = () => {
225
260
226
261
const pageMap = createPageIndex ( allFiles ) ;
227
262
228
- //console.log(pageMap);
229
- //return;
230
263
const processedFiles = files . map ( processFile ) ;
231
264
232
265
const allTested = processedFiles . map ( file => testFile ( pageMap , file ) ) ;
0 commit comments