Updated filter tags.

This commit is contained in:
Mike Cao 2023-03-10 17:49:19 -08:00
parent fd83b63a30
commit 6ba00152c2
4 changed files with 30 additions and 41 deletions

View file

@ -1,30 +1,10 @@
export const urlFilter = data => {
const isValidUrl = url => {
return url !== '' && url !== null;
};
const cleanUrl = url => {
try {
const { pathname } = new URL(url, location.origin);
return pathname;
} catch {
return null;
}
};
const map = data.reduce((obj, { x, y }) => {
if (!isValidUrl(x)) {
return obj;
}
const url = cleanUrl(x);
if (url) {
if (!obj[url]) {
obj[url] = y;
if (x) {
if (!obj[x]) {
obj[x] = y;
} else {
obj[url] += y;
obj[x] += y;
}
}