mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-05-04 01:00:24 +02:00
trim note content
This commit is contained in:
parent
1f038b6384
commit
f432cf65c7
5
.changeset/good-mails-play.md
Normal file
5
.changeset/good-mails-play.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"nostrudel": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Trim note content
|
@ -2,6 +2,7 @@ import { Box, Image, ImageProps, Link, useDisclosure } from "@chakra-ui/react";
|
|||||||
import { EmbedableContent, embedJSX } from "../../helpers/embeds";
|
import { EmbedableContent, embedJSX } from "../../helpers/embeds";
|
||||||
import appSettings from "../../services/app-settings";
|
import appSettings from "../../services/app-settings";
|
||||||
import { ImageGalleryLink } from "../image-gallery";
|
import { ImageGalleryLink } from "../image-gallery";
|
||||||
|
import { useIsMobile } from "../../hooks/use-is-mobile";
|
||||||
|
|
||||||
const BlurredImage = (props: ImageProps) => {
|
const BlurredImage = (props: ImageProps) => {
|
||||||
const { isOpen, onOpen } = useDisclosure();
|
const { isOpen, onOpen } = useDisclosure();
|
||||||
@ -12,24 +13,26 @@ const BlurredImage = (props: ImageProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const EmbeddedImage = ({ src, blue }: { src: string; blue: boolean }) => {
|
||||||
|
const isMobile = useIsMobile();
|
||||||
|
const ImageComponent = blue || !appSettings.value.blurImages ? Image : BlurredImage;
|
||||||
|
const thumbnail = appSettings.value.imageProxy
|
||||||
|
? new URL(`/256,fit/${src}`, appSettings.value.imageProxy).toString()
|
||||||
|
: src;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ImageGalleryLink href={src} target="_blank" display="block" mx="-2">
|
||||||
|
<ImageComponent src={thumbnail} cursor="pointer" maxH={isMobile ? "80vh" : "25vh"} mx={isMobile ? "auto" : "0"} />
|
||||||
|
</ImageGalleryLink>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// note1n06jceulg3gukw836ghd94p0ppwaz6u3mksnnz960d8vlcp2fnqsgx3fu9
|
// note1n06jceulg3gukw836ghd94p0ppwaz6u3mksnnz960d8vlcp2fnqsgx3fu9
|
||||||
export function embedImages(content: EmbedableContent, trusted = false) {
|
export function embedImages(content: EmbedableContent, trusted = false) {
|
||||||
return embedJSX(content, {
|
return embedJSX(content, {
|
||||||
regexp:
|
regexp:
|
||||||
/https?:\/\/([\dA-z\.-]+\.[A-z\.]{2,6})((?:\/[\+~%\/\.\w\-_]*)?\.(?:svg|gif|png|jpg|jpeg|webp|avif))(\??(?:[\?#\-\+=&;%@\.\w_]*)#?(?:[\-\.\!\/\\\w]*))?/i,
|
/https?:\/\/([\dA-z\.-]+\.[A-z\.]{2,6})((?:\/[\+~%\/\.\w\-_]*)?\.(?:svg|gif|png|jpg|jpeg|webp|avif))(\??(?:[\?#\-\+=&;%@\.\w_]*)#?(?:[\-\.\!\/\\\w]*))?/i,
|
||||||
render: (match) => {
|
render: (match) => <EmbeddedImage blue={trusted} src={match[0]} />,
|
||||||
const ImageComponent = trusted || !appSettings.value.blurImages ? Image : BlurredImage;
|
|
||||||
const thumbnail = appSettings.value.imageProxy
|
|
||||||
? new URL(`/256,fit/${match[0]}`, appSettings.value.imageProxy).toString()
|
|
||||||
: match[0];
|
|
||||||
const src = match[0];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ImageGalleryLink href={src} target="_blank" display="block" mx="-2">
|
|
||||||
<ImageComponent src={thumbnail} cursor="pointer" maxW="30rem" w="full" />
|
|
||||||
</ImageGalleryLink>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
name: "Image",
|
name: "Image",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ const EmbeddedNote = ({ note }: { note: NostrEvent }) => {
|
|||||||
</Link>
|
</Link>
|
||||||
</Flex>
|
</Flex>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardBody px="2" pt="0" pb="2">
|
<CardBody p="0">
|
||||||
<NoteContents event={note} trusted={following.includes(note.pubkey)} maxHeight={200} />
|
<NoteContents event={note} trusted={following.includes(note.pubkey)} maxHeight={200} />
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
import { ImageGalleryProvider } from "../image-gallery";
|
import { ImageGalleryProvider } from "../image-gallery";
|
||||||
|
|
||||||
function buildContents(event: NostrEvent | DraftNostrEvent, trusted: boolean = false) {
|
function buildContents(event: NostrEvent | DraftNostrEvent, trusted: boolean = false) {
|
||||||
let content: EmbedableContent = [event.content];
|
let content: EmbedableContent = [event.content.trim()];
|
||||||
|
|
||||||
content = embedLightningInvoice(content);
|
content = embedLightningInvoice(content);
|
||||||
content = embedTweet(content);
|
content = embedTweet(content);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user