forked from Transparency/kgroad-frontend2
Fix news details
This commit is contained in:
1 parent
54ec09afe0
commit
19397689b1
4 files changed
+121
-13
No files matched your search
@@ -8,6 +8,7 @@ import calendar from "./icons/calendar.svg";
|
||||
import ReviewSection from "@/widgets/ReviewSection/ReviewSection";
|
||||
import BreadCrumbs from "@/features/BreadCrumbs/BreadCrumbs";
|
||||
import { Metadata } from "next";
|
||||
import parse from "html-react-parser";
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
@@ -26,6 +27,14 @@ export async function generateMetadata({
|
||||
},
|
||||
};
|
||||
}
|
||||
function convertLinksToHtml(text: string) {
|
||||
const urlPattern =
|
||||
/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[-A-Z0-9+&@#\/%=~_|$])[\s.,;]?/gi;
|
||||
return text.replace(urlPattern, (url) => {
|
||||
const href = url.trim();
|
||||
return `<a href="${href}" target="_blank" rel="noopener noreferrer">${href}</a>`;
|
||||
});
|
||||
}
|
||||
const formatDescription = (text: string) => {
|
||||
return text.replace(/(\r\n|\n|\r)/g, "<br />");
|
||||
};
|
||||
@@ -57,7 +66,8 @@ const NewsDetails = async ({
|
||||
"11": "Ноябрь",
|
||||
"12": "Декабрь",
|
||||
};
|
||||
|
||||
const htmlContentWithLinks = convertLinksToHtml(data.description);
|
||||
const formattedHtmlContent = formatDescription(htmlContentWithLinks);
|
||||
return (
|
||||
<div className="news-details page-padding">
|
||||
<BreadCrumbs />
|
||||
@@ -86,12 +96,9 @@ const NewsDetails = async ({
|
||||
|
||||
<div className="news-details__text">
|
||||
<h3>{data.title}</h3>
|
||||
<div
|
||||
className="news-details__description"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: formatDescription(data.description),
|
||||
}}
|
||||
/>
|
||||
<div className="news-details__description">
|
||||
{parse(formattedHtmlContent)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ReviewSection endpoint="news" id={data.id} />
|
||||
|
||||
Reference in new issue
Block a user