diff options
| author | Pinapelz <yukais@pinapelz.com> | 2025-04-14 16:34:29 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2025-04-14 16:34:29 -0700 |
| commit | 9ffb79ae1764368e863efcbd74f6e6c11f8c58b5 (patch) | |
| tree | c4ed53823b8b4fbdb7880d111eba8f646250ac7f /site | |
| parent | 458561f5934d49e6785226f6ae446093804393e2 (diff) | |
frontend: add regex replacement for markdown inline links and regular urls
makes them clickable
Diffstat (limited to 'site')
| -rw-r--r-- | site/src/components/NewsFeed.tsx | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/site/src/components/NewsFeed.tsx b/site/src/components/NewsFeed.tsx index 311fe75..a9b36cf 100644 --- a/site/src/components/NewsFeed.tsx +++ b/site/src/components/NewsFeed.tsx @@ -71,7 +71,24 @@ export const NewsFeed: React.FC<NewsFeedProps> = ({ newsItems }) => { {/* Content */} <p className="text-sm text-gray-200 whitespace-pre-line mb-2"> - {news.content} + {news.content.split(/(\[.*?\]\(.*?\)|https?:\/\/[^\s]+)/g).map((part, index) => { + const match = part.match(/\[(.*?)\]\((.*?)\)/); + const urlMatch = part.match(/https?:\/\/[^\s]+/); + if (match) { + return ( + <a key={index} href={match[2]} target="_blank" rel="noopener noreferrer" className="text-blue-400 hover:underline"> + {match[1]} + </a> + ); + } else if (urlMatch) { + return ( + <a key={index} href={urlMatch[0]} target="_blank" rel="noopener noreferrer" className="text-blue-400 hover:underline"> + {urlMatch[0]} + </a> + ); + } + return part; + })} </p> </div> |
