Skip to content

Commit

Permalink
Add support for http(s) in visible text
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrootBuck authored and xitanggg committed Jul 4, 2023
1 parent 0e5fe32 commit 453e471
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/app/components/Resume/ResumePDF/ResumePDFProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,37 @@ export const ResumePDFProfile = ({
const Wrapper = ({ children }: { children: React.ReactNode }) => {
if (!shouldUseLinkWrapper) return <>{children}</>;

let urlSrc = "";

switch (key) {
case "email":
return (
<ResumePDFLink src={`mailto:${value}`} isPDF={isPDF}>
{children}
</ResumePDFLink>
);
urlSrc = `mailto:${value}`;
break;

case "phone":
return (
<ResumePDFLink
src={`tel:${value.replace(/[\(\)\s-]/g, "")}`} // This regex "cleans" the number
isPDF={isPDF}
>
{children}
</ResumePDFLink>
);
urlSrc = `tel:${value.replace(/[^\d+]/g, "")}`;
break;

case "url":
let removalCases = ["http://", "https://"];
let http_protocol = "https://";

default:
return (
<ResumePDFLink src={`https://${value}`} isPDF={isPDF}>
{children}
</ResumePDFLink>
);
removalCases.forEach((item) => {
if (value.startsWith(item)) {
value = value.substring(item.length - 1, value.length - 1);
http_protocol = item;
}
});

urlSrc = `${http_protocol}${value}`;
break;
}

return (
<ResumePDFLink src={urlSrc} isPDF={isPDF}>
{children}
</ResumePDFLink>
);
};

return (
Expand Down

0 comments on commit 453e471

Please sign in to comment.