Skip to content

Commit

Permalink
v0.1.0 - fix: email ids getting highlighted as bsky username
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhdaware committed Nov 20, 2024
1 parent 40e4772 commit 7fc69fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ export const formatParagraph = (text: string): string => {
/\b((?:https?:\/\/)?(?:www\.)?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/[a-zA-Z0-9._~:/?#\[\]@!$&'()*+,;=%-]*)?)|@[a-zA-Z0-9._]+/gi;

// Replace URLs with anchor tags
let formattedText = text.replace(urlPattern, (url) => {
let formattedText = text.replace(urlPattern, (url, _a, _b, index) => {


if (url.startsWith("@")) {
if (!url.includes(".")) {
// Probably just random tag and not bsky profile
return url;
}

const charBeforeAt = index > 0 ? text.at(index - 1) : '';
// if character before `@` is not white space or next line, then its probably email id
const isEmail = charBeforeAt?.trim() !== '';

if (isEmail) {
return url;
}

const href = `https://bsky.app/profile/${url.slice(1)}`;
// its a bluesky handle!!
return `<a href="${href}" target="_blank" rel="noopener noreferrer">${url}</a>`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bsky-widget",
"version": "0.1.0",
"version": "0.1.1",
"description": "Profile Card / Widget for Bluesky",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down

0 comments on commit 7fc69fc

Please sign in to comment.