urls added
This commit is contained in:
parent
e3364bb86c
commit
890157a6a6
@ -26,8 +26,8 @@ export default function FeaturedLists() {
|
|||||||
limit: 60,
|
limit: 60,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const uniq = uniqBy((e) => e.id, events);
|
||||||
const processedEvents = uniqBy((e) => getTagValues("d", e.tags), events)
|
const processedEvents = uniqBy((e) => getTagValues("d", e.tags), uniq)
|
||||||
.filter(
|
.filter(
|
||||||
(a) =>
|
(a) =>
|
||||||
!!getTagValues("image", a.tags) ?? !!getTagValues("picture", a.tags),
|
!!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 useCurrentUser from "@/lib/hooks/useCurrentUser";
|
||||||
import { saveEphemeralSigner } from "@/lib/actions/ephemeral";
|
import { saveEphemeralSigner } from "@/lib/actions/ephemeral";
|
||||||
import useLists from "@/lib/hooks/useLists";
|
import useLists from "@/lib/hooks/useLists";
|
||||||
|
import { getUrls } from "@/components/TextRendering";
|
||||||
|
|
||||||
const ShortTextNoteSchema = z.object({
|
const ShortTextNoteSchema = z.object({
|
||||||
content: z.string(),
|
content: z.string(),
|
||||||
@ -51,6 +52,8 @@ export default function ShortTextNoteModal() {
|
|||||||
toast.error("Error connecting");
|
toast.error("Error connecting");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const urls = getUrls(data.content);
|
||||||
|
const urlTags = urls.map((u) => ["r", u]);
|
||||||
if (data.list) {
|
if (data.list) {
|
||||||
const list = lists.find((l) => getTagValues("d", l.tags) === data.list);
|
const list = lists.find((l) => getTagValues("d", l.tags) === data.list);
|
||||||
if (!list) {
|
if (!list) {
|
||||||
@ -83,7 +86,7 @@ export default function ShortTextNoteModal() {
|
|||||||
{
|
{
|
||||||
content: data.content,
|
content: data.content,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: [],
|
tags: [...urlTags],
|
||||||
},
|
},
|
||||||
data.isPrivate,
|
data.isPrivate,
|
||||||
list,
|
list,
|
||||||
@ -99,7 +102,7 @@ export default function ShortTextNoteModal() {
|
|||||||
{
|
{
|
||||||
content: data.content,
|
content: data.content,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: [],
|
tags: [...urlTags],
|
||||||
},
|
},
|
||||||
data.isPrivate,
|
data.isPrivate,
|
||||||
);
|
);
|
||||||
|
@ -3,13 +3,14 @@ import Link from "next/link";
|
|||||||
import ProfileMention from "./ProfileMention";
|
import ProfileMention from "./ProfileMention";
|
||||||
import EventMention from "./EventMention";
|
import EventMention from "./EventMention";
|
||||||
|
|
||||||
const RenderText = ({ text }: { text?: string }) => {
|
|
||||||
if (!text) return null;
|
|
||||||
const Elements: JSX.Element[] = [];
|
|
||||||
const urlRegex =
|
const urlRegex =
|
||||||
/(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))/g;
|
/(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 hashtagRegex = /#\b\w+\b/g;
|
||||||
const nostrPrefixRegex = /nostr:[a-z0-9]+/g;
|
const nostrPrefixRegex = /nostr:[a-z0-9]+/g;
|
||||||
|
|
||||||
|
const RenderText = ({ text }: { text?: string }) => {
|
||||||
|
if (!text) return null;
|
||||||
|
const Elements: JSX.Element[] = [];
|
||||||
// const usernameRegex = /(?:^|\s)\@(\w+)\b/g;
|
// const usernameRegex = /(?:^|\s)\@(\w+)\b/g;
|
||||||
const combinedRegex = new RegExp(
|
const combinedRegex = new RegExp(
|
||||||
`(${urlRegex.source}|${hashtagRegex.source}|${nostrPrefixRegex.source})`,
|
`(${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