diff --git a/app/(app)/app/_sections/FeaturedLists.tsx b/app/(app)/app/_sections/FeaturedLists.tsx index 86b800a..76e8e18 100644 --- a/app/(app)/app/_sections/FeaturedLists.tsx +++ b/app/(app)/app/_sections/FeaturedLists.tsx @@ -26,8 +26,8 @@ export default function FeaturedLists() { limit: 60, }, }); - - const processedEvents = uniqBy((e) => getTagValues("d", e.tags), events) + const uniq = uniqBy((e) => e.id, events); + const processedEvents = uniqBy((e) => getTagValues("d", e.tags), uniq) .filter( (a) => !!getTagValues("image", a.tags) ?? !!getTagValues("picture", a.tags), diff --git a/components/Modals/ShortTextNote.tsx b/components/Modals/ShortTextNote.tsx index d542d99..904a04c 100644 --- a/components/Modals/ShortTextNote.tsx +++ b/components/Modals/ShortTextNote.tsx @@ -12,6 +12,7 @@ import { getTagValues } from "@/lib/nostr/utils"; import useCurrentUser from "@/lib/hooks/useCurrentUser"; import { saveEphemeralSigner } from "@/lib/actions/ephemeral"; import useLists from "@/lib/hooks/useLists"; +import { getUrls } from "@/components/TextRendering"; const ShortTextNoteSchema = z.object({ content: z.string(), @@ -51,6 +52,8 @@ export default function ShortTextNoteModal() { toast.error("Error connecting"); return; } + const urls = getUrls(data.content); + const urlTags = urls.map((u) => ["r", u]); if (data.list) { const list = lists.find((l) => getTagValues("d", l.tags) === data.list); if (!list) { @@ -83,7 +86,7 @@ export default function ShortTextNoteModal() { { content: data.content, kind: 1, - tags: [], + tags: [...urlTags], }, data.isPrivate, list, @@ -99,7 +102,7 @@ export default function ShortTextNoteModal() { { content: data.content, kind: 1, - tags: [], + tags: [...urlTags], }, data.isPrivate, ); diff --git a/components/TextRendering/index.tsx b/components/TextRendering/index.tsx index 7e54f83..d3d9ae9 100644 --- a/components/TextRendering/index.tsx +++ b/components/TextRendering/index.tsx @@ -3,13 +3,14 @@ import Link from "next/link"; import ProfileMention from "./ProfileMention"; import EventMention from "./EventMention"; +const urlRegex = + /(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))/g; +const hashtagRegex = /#\b\w+\b/g; +const nostrPrefixRegex = /nostr:[a-z0-9]+/g; + const RenderText = ({ text }: { text?: string }) => { if (!text) return null; const Elements: JSX.Element[] = []; - const urlRegex = - /(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))/g; - const hashtagRegex = /#\b\w+\b/g; - const nostrPrefixRegex = /nostr:[a-z0-9]+/g; // const usernameRegex = /(?:^|\s)\@(\w+)\b/g; const combinedRegex = new RegExp( `(${urlRegex.source}|${hashtagRegex.source}|${nostrPrefixRegex.source})`, @@ -79,4 +80,10 @@ const RenderText = ({ text }: { text?: string }) => { ); }; -export { RenderText }; +function getUrls(content: string) { + const urls = content.match(urlRegex)?.map((u) => cleanUrl(u)) ?? []; + + return urls; +} + +export { RenderText, getUrls };