Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions components/NoteContent/HyperLinks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { MouseEvent } from "react";
import { Anchor } from "@mantine/core";
import useStyles from "./NoteContent.styles";

export const HyperLink = ({ href }: { href: string }) => {
const { classes } = useStyles();

if (/(gif|jpe?g|tiff?|png|webp|bmp)$/i.test(href)) {
return (
<img
src={href}
alt={href}
style={{ maxHeight: 400, maxWidth: "50%", borderRadius: 12 }}
/>
);
}

return (
<Anchor
className={classes.anchor}
href={href}
onClick={(e: MouseEvent) => e.stopPropagation()}
target="_blank"
rel="noreferrer"
>
{href}
</Anchor>
);
};

export default HyperLink;
19 changes: 4 additions & 15 deletions components/NoteContent/NoteContent.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Fragment, type MouseEvent } from "react";
import { Text, Anchor } from "@mantine/core";
import { Fragment } from "react";
import { Text } from "@mantine/core";
import MentionLink from "./MentionLink";
import { NPUB_NOSTR_URI_REGEX } from "../../constants";
import useStyles from "./NoteContent.styles";
import HyperLink from "./HyperLinks";

const HYPERLINK_REGEX =
/(https?:\/\/[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|])/;

export const NoteContent = ({ content }: { content: string }) => {
const { classes } = useStyles();
const formattingRegEx = new RegExp(
`(?:${NPUB_NOSTR_URI_REGEX.source}|${HYPERLINK_REGEX.source})`,
"gi"
Expand All @@ -24,17 +23,7 @@ export const NoteContent = ({ content }: { content: string }) => {
}

if (HYPERLINK_REGEX.test(part)) {
return (
<Anchor
className={classes.anchor}
href={part}
onClick={(e: MouseEvent) => e.stopPropagation()}
target="_blank"
rel="noreferrer"
>
{part}
</Anchor>
);
return <HyperLink key={index} href={part} />;
}

return <Fragment key={index}>{part}</Fragment>;
Expand Down
8 changes: 8 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ module.exports = withPWA(
eslint: {
ignoreDuringBuilds: true,
},
images: {
remotePatterns: [
{
protocol: "https",
hostname: "**",
},
],
},
webpack(config) {
config.module.rules.push({
test: /\.svg$/i,
Expand Down