Skip to content

Commit

Permalink
Reformat link src logic
Browse files Browse the repository at this point in the history
  • Loading branch information
xitanggg committed Jul 4, 2023
1 parent 453e471 commit d29b899
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions src/app/components/Resume/ResumePDF/ResumePDFProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
break;

case "phone":
urlSrc = `tel:${value.replace(/[^\d+]/g, "")}`;
case "email": {
src = `mailto:${value}`;
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>
);
Expand Down

0 comments on commit d29b899

Please sign in to comment.