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,7 +11,22 @@ 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("://");
if (badge.ForUrl.includes(",")) {
const urls = badge.ForUrl.replaceAll(" ", "").split(",");
for (const url of urls) {
this.processUri(url, badge, goalBadges, urlBadges);
}
} else {
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", "/");
@ -23,8 +38,4 @@ export default abstract class BadgeCache {
urlBadges.set(url, badge);
}
}
BadgeCache.UrlBadges = urlBadges;
BadgeCache.GoalBadges = goalBadges;
}
}