|
|
@@ -7,10 +7,11 @@ const isAnchorLink = (href: string): boolean => {
|
|
|
return href.toString().length > 0 && href[0] === '#';
|
|
|
};
|
|
|
|
|
|
-const isExternalLink = (href: string, siteUrl: URL): boolean => {
|
|
|
- const hrefUrl = new URL(href, siteUrl);
|
|
|
+const isExternalLink = (href: string, siteUrl: string | undefined): boolean => {
|
|
|
+ const baseUrl = new URL(siteUrl ?? 'https://example.com');
|
|
|
+ const hrefUrl = new URL(href, baseUrl);
|
|
|
|
|
|
- return siteUrl.host !== hrefUrl.host;
|
|
|
+ return baseUrl.host !== hrefUrl.host;
|
|
|
};
|
|
|
|
|
|
type Props = Omit<LinkProps, 'href'> & {
|
|
|
@@ -23,15 +24,7 @@ export const NextLink = ({
|
|
|
href, children, className, ...props
|
|
|
}: Props): JSX.Element => {
|
|
|
|
|
|
- const { data: _siteUrl } = useSiteUrl();
|
|
|
-
|
|
|
- let siteUrl: URL;
|
|
|
- try {
|
|
|
- siteUrl = new URL(_siteUrl ?? 'http://example.com');
|
|
|
- }
|
|
|
- catch {
|
|
|
- return <a className={className}>{children}</a>;
|
|
|
- }
|
|
|
+ const { data: siteUrl } = useSiteUrl();
|
|
|
|
|
|
if (href == null) {
|
|
|
return <a className={className}>{children}</a>;
|