@@ -79,7 +79,15 @@ export class WebCrawler {
7979 const sitemapLinks = await this . tryFetchSitemapLinks ( this . initialUrl ) ;
8080 if ( sitemapLinks . length > 0 ) {
8181 let filteredLinks = sitemapLinks
82- . filter ( ( link ) => ! this . visited . has ( link ) && this . filterURL ( link ) )
82+ . filter ( ( link ) => {
83+ let u = link ;
84+ if ( link . startsWith ( "/" ) ) {
85+ u = new URL ( link , this . initialUrl ) . href ;
86+ } else if ( ! link . startsWith ( "#" ) && ! link . startsWith ( "mailto:" ) ) {
87+ u = new URL ( link , this . initialUrl ) . href ;
88+ }
89+ return ! this . visited . has ( u ) && this . filterURL ( u ) ;
90+ } )
8391 . slice ( 0 , this . limit ) ;
8492 return filteredLinks . map ( ( link ) => ( { url : link , html : "" } ) ) ;
8593 }
@@ -119,9 +127,19 @@ export class WebCrawler {
119127 ) ;
120128
121129 const filteredUrls = urls
122- . filter (
123- ( urlObj ) => ! this . visited . has ( urlObj . url ) && this . filterURL ( urlObj . url )
124- )
130+ . filter ( ( urlObj ) => {
131+ let u = urlObj . url ;
132+ if ( urlObj . url . startsWith ( "/" ) ) {
133+ u = new URL ( urlObj . url , this . initialUrl ) . href ;
134+ } else if (
135+ ! urlObj . url . startsWith ( "#" ) &&
136+ ! urlObj . url . startsWith ( "mailto:" )
137+ ) {
138+ u = new URL ( urlObj . url , this . initialUrl ) . href ;
139+ }
140+
141+ return ! this . visited . has ( u ) && this . filterURL ( u ) ;
142+ } )
125143 . slice ( 0 , limit ) ;
126144
127145 return filteredUrls . map ( ( filteredUrl ) => ( {
@@ -222,17 +240,17 @@ export class WebCrawler {
222240 return fullUrl ;
223241 }
224242
225- // Logger.debug (
226- // `Link filtered out: ${fullUrl} with tests: isInternalLink: ${this.isInternalLink(
227- // fullUrl
228- // )}, allowExternalLinks: ${
229- // this.allowExternalLinks
230- // }, isSocialMediaOrEmail: ${this.isSocialMediaOrEmail(
231- // fullUrl
232- // )}, matchesExcludes: ${this.matchesExcludes(
233- // fullUrl
234- // )}, matchesIncludes: ${this.matchesIncludes(fullUrl)}`
235- // );
243+ Logger . trace (
244+ `Link filtered out: ${ fullUrl } with tests: isInternalLink: ${ this . isInternalLink (
245+ fullUrl
246+ ) } , allowExternalLinks: ${
247+ this . allowExternalLinks
248+ } , isSocialMediaOrEmail: ${ this . isSocialMediaOrEmail (
249+ fullUrl
250+ ) } , matchesExcludes: ${ this . matchesExcludes (
251+ fullUrl
252+ ) } , matchesIncludes: ${ this . matchesIncludes ( fullUrl ) } `
253+ ) ;
236254 return null ;
237255 }
238256
0 commit comments