-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid .md files being picked up as a duplicate URL
- Loading branch information
Showing
3 changed files
with
15 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
const URL_REGEX = /(?:https?:\/\/)?(?:[-\w]+\.)+[a-z]{2,18}/gi; | ||
const URL_REGEX = /(?:https?:\/\/)?(?:[-\w]+\.)+[a-z]{2,18}\/?/gi; | ||
const EXCLUSION_LIST = [ | ||
'tachiyomi.org', | ||
'github.com', | ||
'user-images.githubusercontent.com', | ||
'gist.github.com', | ||
]; | ||
// Also file name extensions | ||
const EXCLUDED_DOMAINS = ['.md']; | ||
|
||
export function urlsFromIssueBody(body: string): string[] { | ||
const urls = Array.from(body.matchAll(URL_REGEX)) | ||
.map((url) => cleanUrl(url[0])) | ||
.filter((url) => !EXCLUSION_LIST.includes(url)); | ||
.filter((url) => !EXCLUSION_LIST.includes(url)) | ||
.filter((url) => EXCLUDED_DOMAINS.every((domain) => !url.endsWith(domain))); | ||
return Array.from(new Set(urls)); | ||
} | ||
|
||
export function cleanUrl(url: string): string { | ||
return url.replace(/(https?:\/\/)?(www\.)?/g, '').toLowerCase(); | ||
return url | ||
.toLowerCase() | ||
.replace(/(https?:\/\/)?(www\.)?/g, '') | ||
.replace(/\/$/, ''); | ||
} |