2021-08-20 17:06:26 +02:00
|
|
|
import React from 'react';
|
2021-09-05 18:25:49 +02:00
|
|
|
import styled from 'styled-components';
|
2021-08-20 17:06:26 +02:00
|
|
|
|
|
|
|
type EnrichedLinkProps = {
|
|
|
|
href: string;
|
2021-12-10 14:39:47 +01:00
|
|
|
children: React.ReactNode;
|
|
|
|
};
|
2021-08-20 17:06:26 +02:00
|
|
|
|
2021-09-05 18:25:49 +02:00
|
|
|
const Link = styled.a`
|
|
|
|
font-weight: 600;
|
|
|
|
text-decoration: underline;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const EnrichedLink = (props: EnrichedLinkProps) => {
|
2021-08-20 17:06:26 +02:00
|
|
|
// Is external URL or is a media URL
|
2021-12-10 14:39:47 +01:00
|
|
|
const isExternalUrl = /(^http(s)?:\/\/)|(\.(png|svg|jpeg|jpg)$)/.test(
|
|
|
|
props.href
|
|
|
|
);
|
|
|
|
|
|
|
|
const linkProps: Record<string, string> = {
|
|
|
|
target: '_self',
|
|
|
|
...(isExternalUrl
|
|
|
|
? {
|
|
|
|
rel: 'nofollow',
|
|
|
|
target: '_blank',
|
|
|
|
}
|
|
|
|
: {}),
|
|
|
|
};
|
2021-08-20 17:06:26 +02:00
|
|
|
|
|
|
|
return (
|
2021-12-10 14:39:47 +01:00
|
|
|
<Link href={props.href} {...linkProps}>
|
2021-08-20 17:06:26 +02:00
|
|
|
{props.children}
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
};
|
2021-09-05 18:25:49 +02:00
|
|
|
|
|
|
|
export default EnrichedLink;
|