support multiple urls in the ForUrl field

This commit is contained in:
Holly Stubbs 2024-10-08 01:19:45 +01:00
parent 2f3c5b7769
commit d7330dcec3
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E

View file

@ -11,20 +11,31 @@ export default abstract class BadgeCache {
const urlBadges = new FunkyArray<string, Badge>();
const goalBadges = new FunkyArray<string, Badge>();
for (const badge of badges) {
const urlParts = badge.ForUrl.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);
if (badge.ForUrl.includes(",")) {
const urls = badge.ForUrl.replaceAll(" ", "").split(",");
for (const url of urls) {
this.processUri(url, badge, goalBadges, urlBadges);
}
} else {
urlBadges.set(url, badge);
this.processUri(badge.ForUrl, badge, goalBadges, urlBadges);
}
}
BadgeCache.UrlBadges = urlBadges;
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);
}
}
}