Skip to content

Commit 4dd4418

Browse files
committed
Add linkify to news body and fix ESLint warning
1 parent 8c8b583 commit 4dd4418

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

frontend-next-migration/src/preparedPages/NewsPages/ui/NewsElementPage/ui/NewsElementPage.tsx

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,38 @@ import { Button, ButtonSize, ButtonTheme } from '@/shared/ui/Button';
1515
import chevronleft from '@/shared/assets/icons/ChevronLeftBlack.svg';
1616
import chevronright from '@/shared/assets/icons/ChevronRightBlack.svg';
1717
import { useRouter, useParams } from 'next/navigation';
18+
import { linkify } from '@/shared/ui/v2/Chatbot/utils/linkify';
1819
import { useClientTranslation } from '@/shared/i18n';
1920
import { NewsCard } from '@/widgets/NewsCard';
2021
import { ShareButton } from '@/shared/ui/v2/ShareButton';
2122

23+
type HeroImageProps = {
24+
picture?: string;
25+
};
26+
27+
const HeroImage = ({ picture }: HeroImageProps) => {
28+
if (!picture) return <div className={cls.noImageContainer} />;
29+
30+
return (
31+
<div className={cls.imageContainer}>
32+
<Image
33+
src={picture}
34+
alt=""
35+
className={cls.imageBlur}
36+
width={100}
37+
height={600}
38+
/>
39+
<Image
40+
src={picture}
41+
alt=""
42+
className={cls.image}
43+
width={100}
44+
height={600}
45+
/>
46+
</div>
47+
);
48+
};
49+
2250
const NewsElementPage = () => {
2351
useScrollToTop();
2452
const params = useParams();
@@ -45,6 +73,9 @@ const NewsElementPage = () => {
4573
const picture = post.titlePicture?.id
4674
? `${directusBaseUrl}/assets/${post.titlePicture.id}`
4775
: undefined;
76+
77+
const bodyHtml = linkify(post?.bodyText ?? '');
78+
4879
return (
4980
<Container>
5081
<div className={cls.navButtons}>
@@ -84,26 +115,7 @@ const NewsElementPage = () => {
84115
</Button>
85116
</div>
86117
<div className={classNames(cls.NewsElementPage)}>
87-
{picture ? (
88-
<div className={cls.imageContainer}>
89-
<Image
90-
src={picture}
91-
alt={''}
92-
className={cls.imageBlur}
93-
width={100}
94-
height={600}
95-
/>
96-
<Image
97-
src={picture}
98-
alt={''}
99-
className={cls.image}
100-
width={100}
101-
height={600}
102-
/>
103-
</div>
104-
) : (
105-
<div className={cls.noImageContainer} />
106-
)}
118+
<HeroImage picture={picture} />
107119

108120
<h1 className={cls.title}>{post?.title}</h1>
109121

@@ -114,7 +126,10 @@ const NewsElementPage = () => {
114126
<span className={cls.date}>{post?.date || 'Date/Time'}</span>
115127
</div>
116128

117-
<p className={cls.text}>{post?.bodyText}</p>
129+
<div
130+
className={cls.text}
131+
dangerouslySetInnerHTML={{ __html: bodyHtml }}
132+
/>
118133

119134
<div className={cls.shareButton}>
120135
<ShareButton>

frontend-next-migration/src/shared/ui/v2/Chatbot/utils/linkify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ export function linkify(text: string): string {
2929
const hrefRaw = url.startsWith('www.') ? `https://${url}` : url;
3030
const href = encodeURI(hrefRaw).replace(/"/g, '&quot;');
3131

32-
return `<a href="${href}" style="color:#121212; text-decoration:underline;">${url}</a>${escapeHtml(trailing)}`;
32+
return `<a href="${href}" target="_blank" rel="noopener noreferrer" style="color:#121212; text-decoration:underline;">${url}</a>${escapeHtml(trailing)}`;
3333
});
3434
}

0 commit comments

Comments
 (0)