Skip to content

Commit

Permalink
fix: Resolves Incorrect Position issue.
Browse files Browse the repository at this point in the history
closes #164
  • Loading branch information
towfiqi committed Feb 15, 2024
1 parent e5ad7a3 commit 0e64b95
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion utils/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ export const getSerp = (domainURL:string, result:SearchResult[]) : SERPObject =>
if (result.length === 0 || !domainURL) { return { postion: 0, url: '' }; }
const URLToFind = new URL(domainURL.includes('https://') ? domainURL : `https://${domainURL}`);
const theURL = URLToFind.hostname + URLToFind.pathname;
const isURL = URLToFind.pathname !== '/';
const foundItem = result.find((item) => {
const itemURL = new URL(item.url.includes('https://') ? item.url : `https://${item.url}`);
return theURL === itemURL.hostname + itemURL.pathname || `${theURL}/` === itemURL.hostname + itemURL.pathname;
if (isURL && `${theURL}/` === itemURL.hostname + itemURL.pathname) {
return true;
}
return URLToFind.hostname === itemURL.hostname;
});
return { postion: foundItem ? foundItem.position : 0, url: foundItem && foundItem.url ? foundItem.url : '' };
};
Expand Down

0 comments on commit 0e64b95

Please sign in to comment.