Updated types
This commit is contained in:
22
src/components/link-replace.tsx
Normal file
22
src/components/link-replace.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Route } from "next"
|
||||
import Link from "next/link"
|
||||
|
||||
export function ReplaceLinks({ text }: { text: string }) {
|
||||
const regex = /(https?:\/\/[^\s/$.?#].[^\s]*)/g
|
||||
const parts = text.split(regex)
|
||||
|
||||
return (
|
||||
<div>
|
||||
{parts.map((part, i) => {
|
||||
if (regex.test(part)) {
|
||||
return (
|
||||
<Link key={i} href={part as Route} target="_blank">
|
||||
{part}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
return <span key={i}>{part}</span>
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user