@@ -223,11 +223,16 @@ function isNonHttpSchema(url) {
223223 * @param {object } options
224224 * @param {string } options.htmlFilePath
225225 * @param {string } options.rootDir
226+ * @param {string } options.absoluteBaseUrl
226227 * @param {function(string): boolean } options.ignoreUsage
227228 */
228- async function resolveLinks ( links , { htmlFilePath, rootDir, ignoreUsage } ) {
229+ async function resolveLinks ( links , { htmlFilePath, rootDir, ignoreUsage, absoluteBaseUrl } ) {
229230 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 ;
231236
232237 const usageObj = {
233238 attribute : hrefObj . attribute ,
@@ -252,8 +257,6 @@ async function resolveLinks(links, { htmlFilePath, rootDir, ignoreUsage }) {
252257 } else if ( valueFile === '' && anchor !== '' ) {
253258 addLocalFile ( htmlFilePath , anchor , usageObj ) ;
254259 } else if ( value . startsWith ( '//' ) || value . startsWith ( 'http' ) ) {
255- // TODO: handle external urls
256- // external url - we do not handle that (yet)
257260 addExternalLink ( htmlFilePath , usageObj ) ;
258261 } else if ( value . startsWith ( '/' ) ) {
259262 const filePath = path . join ( rootDir , valueFile ) ;
@@ -328,7 +331,7 @@ async function validateExternalLinks(checkExternalLinks) {
328331 * @param {string } rootDir
329332 * @param {Options } opts?
330333 */
331- export async function validateFiles ( files , rootDir , opts ) {
334+ export async function prepareFiles ( files , rootDir , opts ) {
332335 await parserReferences . prepareWasm ( saxWasmBuffer ) ;
333336 await parserIds . prepareWasm ( saxWasmBuffer ) ;
334337
@@ -350,14 +353,27 @@ export async function validateFiles(files, rootDir, opts) {
350353 for ( const htmlFilePath of files ) {
351354 const { links } = await extractReferences ( htmlFilePath ) ;
352355 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+ } ) ;
354362 }
363+ return { checkLocalFiles, checkExternalLinks, numberLinks } ;
364+ }
365+
366+ /**
367+ * @param {* } param0
368+ * @returns
369+ */
370+ export async function validateFiles ( { checkLocalFiles, validateExternals, checkExternalLinks } ) {
355371 await validateLocalFiles ( checkLocalFiles ) ;
356- if ( opts ?. validateExternals ) {
372+ if ( validateExternals ) {
357373 await validateExternalLinks ( checkExternalLinks ) ;
358374 }
359375
360- return { errors : errors , numberLinks : numberLinks } ;
376+ return { errors } ;
361377}
362378
363379/**
@@ -367,6 +383,14 @@ export async function validateFiles(files, rootDir, opts) {
367383export async function validateFolder ( inRootDir , opts ) {
368384 const rootDir = path . resolve ( inRootDir ) ;
369385 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+
371395 return errors ;
372396}
0 commit comments