Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from neynarxyz/ds/neyn-1981-fix-cast-linking
Browse files Browse the repository at this point in the history
fix: make sure `useLinkifyBio` doesn't pick up other `/` instances
  • Loading branch information
dylsteck authored Jun 27, 2024
2 parents 7439ab3 + 14dc6b4 commit 14d7849
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/react",
"version": "0.4.6",
"version": "0.4.7",
"description": "Farcaster frontend component library powered by Neynar",
"main": "dist/bundle.cjs.js",
"module": "dist/bundle.es.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { styled } from "@pigment-css/react";

const WARPCAST_DOMAIN = "https://warpcast.com";

const channelRegex = /\/\w+/g;
const channelRegex = /(^|\s)\/\w+/g;
const mentionRegex = /@\w+/g;
const urlRegex = /((https?:\/\/)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})(\/[^\s]*)?)/g;
const combinedRegex = new RegExp(
Expand All @@ -13,7 +13,7 @@ const combinedRegex = new RegExp(

const generateUrl = (match: string): string => {
if (channelRegex.test(match)) {
return `${WARPCAST_DOMAIN}/~/channel${match}`;
return `${WARPCAST_DOMAIN}/~/channel${match.trim()}`;
} else if (mentionRegex.test(match)) {
return `${WARPCAST_DOMAIN}/${match.substring(1)}`;
} else if (urlRegex.test(match)) {
Expand Down Expand Up @@ -41,7 +41,7 @@ export const useLinkifyBio = (text: string): React.ReactNode[] => {
const url = generateUrl(match[0]);
elements.push(
<StyledLink key={matchIndex} href={url} target="_blank">
{match[0]}
{match[0].trim()}
</StyledLink>
);

Expand All @@ -53,4 +53,4 @@ export const useLinkifyBio = (text: string): React.ReactNode[] => {
}

return elements;
};
};

0 comments on commit 14d7849

Please sign in to comment.