added regex for links in sitemap
This commit is contained in:
@@ -64,6 +64,14 @@ export class WebCrawler {
|
|||||||
private filterLinks(sitemapLinks: string[], limit: number, maxDepth: number): string[] {
|
private filterLinks(sitemapLinks: string[], limit: number, maxDepth: number): string[] {
|
||||||
return sitemapLinks
|
return sitemapLinks
|
||||||
.filter((link) => {
|
.filter((link) => {
|
||||||
|
|
||||||
|
// if link is not a complete url, add the base url
|
||||||
|
link = link.trim();
|
||||||
|
const isCompleteUrl = new RegExp('^(?:[a-z+]+:)?//', 'i');
|
||||||
|
if (!isCompleteUrl.test(link)){
|
||||||
|
link = this.baseUrl + link;
|
||||||
|
}
|
||||||
|
|
||||||
const url = new URL(link);
|
const url = new URL(link);
|
||||||
const path = url.pathname;
|
const path = url.pathname;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user