%PDF- %PDF-
Direktori : /proc/self/root/var/www/html/pages/news/[slug]/ |
Current File : //proc/self/root/var/www/html/pages/news/[slug]/index.js |
import { useEffect } from "react"; import News from "../../../src/Components/News"; import Contact from "../../../src/Components/Contact"; import Image from "next/image"; import parse from "html-react-parser"; import CustomHead from "../../../src/Components/Global/CustomHead"; import gsap from "gsap"; import ScrollTrigger from "gsap/dist/ScrollTrigger"; gsap.registerPlugin(ScrollTrigger); function NewsDetails({ data, seo }) { const date = new Date(data?.date); const options = { month: "long" }; const longMonth = new Intl.DateTimeFormat("en-US", options).format(date); const dateDay = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate(); const dateYear = date.getFullYear(); useEffect(() => { window.scrollTo({ top: 0, left: 0, behavior: "smooth", }); }, []); return ( <> <CustomHead data={seo} /> <div className="mainNewsDetails"> <div className="detailsContent"> <div className="info"> <span> {longMonth} {dateDay}, {dateYear} </span> <h1>{parse(data?.title?.rendered)}</h1> </div> {/* <div className="image"> <Image src={data?.featured_image_url} alt="" width={1546} height={773} objectFit="contain" /> </div> */} <div className="dummyText">{parse(data?.content?.rendered)}</div> <div className="image"> {/* <Image src={x.image} width={1546} height={773} /> */} </div> </div> <div className="news"> <News data={data?.related} related={true} titleNews={data?.related?.title} /> </div> <Contact /> </div> </> ); } export default NewsDetails; export async function getServerSideProps(ctx) { const slug = ctx.query.slug; const res = await fetch( `https://api.atvbuggy-dubrovnik.com/wp-json/wp/v2/posts?slug=${slug}` ) .then((response) => response.json()) .then((data) => data); if (!res) { return { notFound: true, }; } return { props: { data: res[0], seo: res[0].yoast_head_json, }, }; }