Fix internal link recognition

There is a problem with regex between Node and browser, and since Next runs the component on both, this create an error.

`Prop `rel` did not match. Server: "null" Client: "noopener nofollow noreferrer"`

This simplifies the implementation and fixes the above error.
This commit is contained in:
Marcus Blättermann 2022-11-30 01:35:05 +01:00
parent c0fa92190c
commit de902ca878
No known key found for this signature in database
GPG Key ID: A1E1F04008AC450D

View File

@ -7,9 +7,7 @@ import Icon from './icon'
import classes from '../styles/link.module.sass'
import { isString, isImage } from './util'
const internalRegex =
/(http(s?)):\/\/(prodi.gy|spacy.io|irl.spacy.io|explosion.ai|course.spacy.io)/gi
const listUrlInternal = ['prodi.gy', 'spacy.io', 'explosion.ai']
const Whitespace = ({ children }) => (
// Ensure that links are always wrapped in spaces
<> {children} </>
@ -71,7 +69,8 @@ export default function Link({
</Wrapper>
)
}
const isInternal = internalRegex.test(dest)
const isInternal = listUrlInternal.some((urlInternal) => dest.includes(urlInternal))
const relTarget = isInternal ? {} : { rel: 'noopener nofollow noreferrer', target: '_blank' }
return (
<Wrapper>