urls added
This commit is contained in:
parent
e3364bb86c
commit
890157a6a6
@ -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),
|
||||
|
@ -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,
|
||||
);
|
||||
|
@ -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 };
|
||||
|
Loading…
x
Reference in New Issue
Block a user