import Link from "next/link";
import Image from "next/image";
export function validURL(str) {
const pattern = new RegExp(
"^(https?:\\/\\/)?" + // protocol
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
"((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
"(\\:\\d+)?(\\/[-a-z\\d%_.~+$]*)*" + // port and path
"(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
"(\\#[-a-z\\d_]*)?$",
"i"
); // fragment locator
return !!pattern.test(str);
}
export function replaceWithImageTags(index, str, emoji_path) {
if (index % 2 === 0) {
return
{`${str}`}
;
} else {
return (
<>
>
);
}
}
export function formatCustomEmoji(str, emoji_paths) {
const emoji_pattern = new RegExp(/(:[A-Za-z_-]+:)/, "g");
const values = emoji_pattern[Symbol.split](str);
if (Boolean(emoji_paths)) {
return (
<>
{Object.keys(values).map((v) =>
replaceWithImageTags(v, values[v], emoji_paths[values[v]])
)}
>
);
} else {
return <>>;
}
}
export function renderPossibleURLField(field, emoji_paths) {
if (validURL(field)) {
return (
{field}
);
} else {
return (
{formatCustomEmoji(field, emoji_paths)}
);
}
}
export function renderPossibleFields(fields, emoji_paths) {
if (Boolean(fields)) {
return Object.keys(fields).map((field) => (
{renderPossibleURLField(field, emoji_paths)}
{renderPossibleURLField(fields[field], emoji_paths)}
));
} else {
return <>>;
}
}
export function renderPossibleBio(bio, emoji_paths) {
if (Boolean(bio)) {
let bioarray = bio.split("\n");
bioarray = bioarray.slice(0, bioarray.length - 1);
const biodict = Object.assign({}, bioarray);
return Object.keys(biodict).map((bio) => (
{biodict[bio] == "" ? (
) : (
formatCustomEmoji(biodict[bio], emoji_paths)
)}
));
} else {
return <>>;
}
}
export default function PartnerCard({
src,
alt,
url,
fields,
bio,
user,
emoji_paths,
}) {
const finalsrc = Boolean(src) ? src : "/images/logo.png";
return (
{renderPossibleBio(bio, emoji_paths)}
{`- @${user}`}
{renderPossibleFields(fields, emoji_paths)}
);
}