support multiple urls in the ForUrl field
This commit is contained in:
parent
2f3c5b7769
commit
d7330dcec3
1 changed files with 20 additions and 9 deletions
|
@ -11,20 +11,31 @@ export default abstract class BadgeCache {
|
||||||
const urlBadges = new FunkyArray<string, Badge>();
|
const urlBadges = new FunkyArray<string, Badge>();
|
||||||
const goalBadges = new FunkyArray<string, Badge>();
|
const goalBadges = new FunkyArray<string, Badge>();
|
||||||
for (const badge of badges) {
|
for (const badge of badges) {
|
||||||
const urlParts = badge.ForUrl.split("://");
|
if (badge.ForUrl.includes(",")) {
|
||||||
let url = urlParts[1].replace("www.", "").toLowerCase().replace(".htm", "").replace(".html", "");
|
const urls = badge.ForUrl.replaceAll(" ", "").split(",");
|
||||||
if (url.endsWith("/index")) {
|
for (const url of urls) {
|
||||||
url = url.replace("/index", "/");
|
this.processUri(url, badge, goalBadges, urlBadges);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (urlParts[0] === "mp") {
|
|
||||||
goalBadges.set(url, badge);
|
|
||||||
} else {
|
} else {
|
||||||
urlBadges.set(url, badge);
|
this.processUri(badge.ForUrl, badge, goalBadges, urlBadges);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BadgeCache.UrlBadges = urlBadges;
|
BadgeCache.UrlBadges = urlBadges;
|
||||||
BadgeCache.GoalBadges = goalBadges;
|
BadgeCache.GoalBadges = goalBadges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static processUri(uri:string, badge: Badge, goalBadges: FunkyArray<string, Badge>, urlBadges: FunkyArray<string, Badge>) {
|
||||||
|
const urlParts = uri.split("://");
|
||||||
|
let url = urlParts[1].replace("www.", "").toLowerCase().replace(".htm", "").replace(".html", "");
|
||||||
|
if (url.endsWith("/index")) {
|
||||||
|
url = url.replace("/index", "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (urlParts[0] === "mp") {
|
||||||
|
goalBadges.set(url, badge);
|
||||||
|
} else {
|
||||||
|
urlBadges.set(url, badge);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue