Fix description for news

This commit is contained in:
ariari04 2024-09-03 11:35:13 +06:00
parent c3697c9e55
commit 54ec09afe0

View File

@ -14,9 +14,7 @@ export async function generateMetadata({
}: { }: {
params: { id: string }; params: { id: string };
}): Promise<Metadata> { }): Promise<Metadata> {
const response = await apiInstance.get<INews>( const response = await apiInstance.get<INews>(`/news/${params.id}/`);
`/news/${params.id}/`
);
return { return {
title: response.data.title, title: response.data.title,
@ -28,6 +26,9 @@ export async function generateMetadata({
}, },
}; };
} }
const formatDescription = (text: string) => {
return text.replace(/(\r\n|\n|\r)/g, "<br />");
};
const NewsDetails = async ({ const NewsDetails = async ({
params, params,
@ -35,9 +36,7 @@ const NewsDetails = async ({
params: { id: string; новость: string }; params: { id: string; новость: string };
}) => { }) => {
const getNewsById = async () => { const getNewsById = async () => {
const response = await apiInstance.get<INews>( const response = await apiInstance.get<INews>(`/news/${params.id}/`);
`/news/${params.id}/`
);
return response.data; return response.data;
}; };
@ -71,9 +70,9 @@ const NewsDetails = async ({
<Image src={calendar} alt="Calendar Icon" /> <Image src={calendar} alt="Calendar Icon" />
<p> <p>
{months[data.created_at.slice(5, 7)]}{" "} {months[data.created_at.slice(5, 7)]}{" "}
{data.created_at.slice(5, 7).slice(0, 1) === "0" {data.created_at.slice(8, 10) === "0"
? data.created_at.slice(6, 7) ? data.created_at.slice(9, 10)
: data.created_at.slice(5, 7)} : data.created_at.slice(8, 10)}
, {data.created_at.slice(0, 4)} , {data.created_at.slice(0, 4)}
</p> </p>
</div> </div>
@ -87,7 +86,12 @@ const NewsDetails = async ({
<div className="news-details__text"> <div className="news-details__text">
<h3>{data.title}</h3> <h3>{data.title}</h3>
<p>{data.description}</p> <div
className="news-details__description"
dangerouslySetInnerHTML={{
__html: formatDescription(data.description),
}}
/>
</div> </div>
<ReviewSection endpoint="news" id={data.id} /> <ReviewSection endpoint="news" id={data.id} />