1
mirror of https://github.com/xitanggg/open-resume synced 2024-11-03 09:19:21 +01:00

Reformat link src logic

This commit is contained in:
Xitang 2023-07-03 21:44:56 -07:00 committed by Xitang Zhao
parent 453e471f8b
commit d29b899134

View File

@ -56,34 +56,23 @@ export const ResumePDFProfile = ({
const Wrapper = ({ children }: { children: React.ReactNode }) => {
if (!shouldUseLinkWrapper) return <>{children}</>;
let urlSrc = "";
let src = "";
switch (key) {
case "email":
urlSrc = `mailto:${value}`;
case "email": {
src = `mailto:${value}`;
break;
case "phone":
urlSrc = `tel:${value.replace(/[^\d+]/g, "")}`;
break;
case "url":
let removalCases = ["http://", "https://"];
let http_protocol = "https://";
removalCases.forEach((item) => {
if (value.startsWith(item)) {
value = value.substring(item.length - 1, value.length - 1);
http_protocol = item;
}
});
urlSrc = `${http_protocol}${value}`;
}
case "phone": {
src = `tel:${value.replace(/[^\d+]/g, "")}`; // Keep only + and digits
break;
}
default: {
src = value.startsWith("http") ? value : `https://${value}`;
}
}
return (
<ResumePDFLink src={urlSrc} isPDF={isPDF}>
<ResumePDFLink src={src} isPDF={isPDF}>
{children}
</ResumePDFLink>
);