@@ -223,11 +223,16 @@ function isNonHttpSchema(url) {
223
223
* @param {object } options
224
224
* @param {string } options.htmlFilePath
225
225
* @param {string } options.rootDir
226
+ * @param {string } options.absoluteBaseUrl
226
227
* @param {function(string): boolean } options.ignoreUsage
227
228
*/
228
- async function resolveLinks ( links , { htmlFilePath, rootDir, ignoreUsage } ) {
229
+ async function resolveLinks ( links , { htmlFilePath, rootDir, ignoreUsage, absoluteBaseUrl } ) {
229
230
for ( const hrefObj of links ) {
230
- const { value, anchor } = getValueAndAnchor ( hrefObj . value ) ;
231
+ const { value : rawValue , anchor } = getValueAndAnchor ( hrefObj . value ) ;
232
+
233
+ const value = rawValue . startsWith ( absoluteBaseUrl )
234
+ ? rawValue . substring ( absoluteBaseUrl . length )
235
+ : rawValue ;
231
236
232
237
const usageObj = {
233
238
attribute : hrefObj . attribute ,
@@ -252,8 +257,6 @@ async function resolveLinks(links, { htmlFilePath, rootDir, ignoreUsage }) {
252
257
} else if ( valueFile === '' && anchor !== '' ) {
253
258
addLocalFile ( htmlFilePath , anchor , usageObj ) ;
254
259
} else if ( value . startsWith ( '//' ) || value . startsWith ( 'http' ) ) {
255
- // TODO: handle external urls
256
- // external url - we do not handle that (yet)
257
260
addExternalLink ( htmlFilePath , usageObj ) ;
258
261
} else if ( value . startsWith ( '/' ) ) {
259
262
const filePath = path . join ( rootDir , valueFile ) ;
@@ -328,7 +331,7 @@ async function validateExternalLinks(checkExternalLinks) {
328
331
* @param {string } rootDir
329
332
* @param {Options } opts?
330
333
*/
331
- export async function validateFiles ( files , rootDir , opts ) {
334
+ export async function prepareFiles ( files , rootDir , opts ) {
332
335
await parserReferences . prepareWasm ( saxWasmBuffer ) ;
333
336
await parserIds . prepareWasm ( saxWasmBuffer ) ;
334
337
@@ -350,14 +353,27 @@ export async function validateFiles(files, rootDir, opts) {
350
353
for ( const htmlFilePath of files ) {
351
354
const { links } = await extractReferences ( htmlFilePath ) ;
352
355
numberLinks += links . length ;
353
- await resolveLinks ( links , { htmlFilePath, rootDir, ignoreUsage } ) ;
356
+ await resolveLinks ( links , {
357
+ htmlFilePath,
358
+ rootDir,
359
+ ignoreUsage,
360
+ absoluteBaseUrl : opts ?. absoluteBaseUrl ,
361
+ } ) ;
354
362
}
363
+ return { checkLocalFiles, checkExternalLinks, numberLinks } ;
364
+ }
365
+
366
+ /**
367
+ * @param {* } param0
368
+ * @returns
369
+ */
370
+ export async function validateFiles ( { checkLocalFiles, validateExternals, checkExternalLinks } ) {
355
371
await validateLocalFiles ( checkLocalFiles ) ;
356
- if ( opts ?. validateExternals ) {
372
+ if ( validateExternals ) {
357
373
await validateExternalLinks ( checkExternalLinks ) ;
358
374
}
359
375
360
- return { errors : errors , numberLinks : numberLinks } ;
376
+ return { errors } ;
361
377
}
362
378
363
379
/**
@@ -367,6 +383,14 @@ export async function validateFiles(files, rootDir, opts) {
367
383
export async function validateFolder ( inRootDir , opts ) {
368
384
const rootDir = path . resolve ( inRootDir ) ;
369
385
const files = await listFiles ( '**/*.html' , rootDir ) ;
370
- const { errors } = await validateFiles ( files , rootDir , opts ) ;
386
+
387
+ const { checkLocalFiles, checkExternalLinks } = await prepareFiles ( files , rootDir , opts ) ;
388
+
389
+ const { errors } = await validateFiles ( {
390
+ checkLocalFiles,
391
+ validateExternals : opts ?. validateExternals ,
392
+ checkExternalLinks,
393
+ } ) ;
394
+
371
395
return errors ;
372
396
}
0 commit comments