fix: seo friendly
This commit is contained in:
+59
-105
@@ -1,105 +1,59 @@
|
||||
import React from 'react'
|
||||
import {
|
||||
MDBCard,
|
||||
MDBCardImage,
|
||||
MDBCardBody,
|
||||
MDBCardTitle,
|
||||
MDBCardText,
|
||||
MDBRow,
|
||||
MDBCol,
|
||||
MDBContainer,
|
||||
MDBCardHeader,
|
||||
MDBBtn,
|
||||
MDBIcon,
|
||||
MDBInputGroupText,
|
||||
MDBTypography
|
||||
} from 'mdb-react-ui-kit'
|
||||
import axios from 'axios'
|
||||
import Link from 'next/link'
|
||||
import AppContainer from './appContainer'
|
||||
import { useRouter } from 'next/router'
|
||||
import { AppUrl } from '../lib/api'
|
||||
import { DownloadIcon } from '@chakra-ui/icons'
|
||||
|
||||
const News = ({ data, children }) => {
|
||||
const router = useRouter()
|
||||
const query = router.query.list
|
||||
|
||||
const dataPage = (
|
||||
<div className='lg:mx-20 sm:mx-5'>
|
||||
<h5 style={{ marginTop: '2rem' }} className={'right-align font-weight-bold'}>
|
||||
اطلاعیه ها{' '}
|
||||
</h5>
|
||||
<hr />
|
||||
<div>
|
||||
<MDBTypography
|
||||
style={{ direction: 'rtl', borderRadius: '6px solid', borderRight: '6px solid #1266f1', borderLeft: 'none' }}
|
||||
note
|
||||
noteColor='primary'
|
||||
>
|
||||
<DownloadIcon className={'ml-2'} />
|
||||
<a
|
||||
title={'دانلود دفترچه معرفی و فروش سهام عمومی بیمارستان تخصصی مهر ایرانیان پرند'}
|
||||
download
|
||||
href={'./take-stock.pdf'}
|
||||
>
|
||||
{' '}
|
||||
دانلود دفترچه معرفی و فروش سهام عمومی بیمارستان تخصصی مهر پرند
|
||||
</a>
|
||||
</MDBTypography>
|
||||
<MDBTypography
|
||||
style={{ direction: 'rtl', borderRadius: '6px solid', borderRight: '6px solid #1266f1', borderLeft: 'none' }}
|
||||
note
|
||||
noteColor='primary'
|
||||
>
|
||||
<DownloadIcon className={'ml-2'} />
|
||||
<a
|
||||
title={'دانلود طرح توجیهی بیمارستان تخصصی مهر ایرانیان پرند'}
|
||||
download
|
||||
href={'./Explanatory_plan_of_Mehr_ranian_Parand_Hospital.pdf'}
|
||||
>
|
||||
{' '}
|
||||
دانلود طرح توجیهی بیمارستان تخصصی مهر ایرانیان پرند
|
||||
</a>
|
||||
</MDBTypography>
|
||||
</div>
|
||||
<br />
|
||||
{/* <MDBRow dir={'rtl'} className='row-cols-1 row-cols-md-3 g-4'>
|
||||
{data && data.map(({ id, slug, title }) => (
|
||||
<MDBCol key={id}>
|
||||
<Link href={`page/news/${id}`} >
|
||||
<MDBCard className='mb-3 h-3/12 new-card'>
|
||||
<MDBCardHeader title={title} className={'right-align bk-med RTL font-weight-bold border-bottom-1 border-white '}>{title} </MDBCardHeader>
|
||||
<MDBCardBody>
|
||||
<MDBCardText className={'right-align RTL text-summery'}>
|
||||
{slug}
|
||||
</MDBCardText>
|
||||
<div className={'flex justify-content-end'}>
|
||||
<MDBBtn rounded className=' RTL text-primary-teal bg-white'>
|
||||
مشاهده
|
||||
</MDBBtn>
|
||||
</div>
|
||||
</MDBCardBody>
|
||||
</MDBCard>
|
||||
</Link>
|
||||
</MDBCol>
|
||||
))}
|
||||
</MDBRow> */}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
return <div>{/* {query ? <AppContainer children={dataPage} title={'اطلاعیه ها '} /> : dataPage} */}</div>
|
||||
}
|
||||
|
||||
export default News
|
||||
|
||||
export const getServerSideProps = async context => {
|
||||
// const allPostsData = await axios.get(AppUrl('news'))
|
||||
// const data = await allPostsData.data
|
||||
return {
|
||||
props: {
|
||||
data: null,
|
||||
fallback: false
|
||||
} // will be passed to the page component as props
|
||||
}
|
||||
}
|
||||
import React from 'react'
|
||||
import axios from 'axios'
|
||||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/router'
|
||||
import AppContainer from './appContainer'
|
||||
import { AppUrl } from '../lib/api'
|
||||
import { newsSeo } from '../lib/seo'
|
||||
|
||||
export default function News({ data = [], unavailable = false, children }) {
|
||||
const router = useRouter()
|
||||
const isHome = router.pathname === '/'
|
||||
const posts = (Array.isArray(data) ? data : []).filter(post => post && post.title && /^\d+$/.test(String(post.id)))
|
||||
if (isHome && posts.length === 0) return null
|
||||
|
||||
const content = (
|
||||
<section className='lg:mx-20 sm:mx-5 my-5 RTL' aria-labelledby='news-title'>
|
||||
{isHome ? <h2 id='news-title'>اخبار و اطلاعیهها</h2> : <h1 id='news-title'>اخبار و اطلاعیههای بیمارستان مهر پرند</h1>}
|
||||
<hr />
|
||||
{unavailable && <p role='status'>دریافت اخبار موقتاً امکانپذیر نیست. لطفاً کمی بعد دوباره مراجعه کنید.</p>}
|
||||
<div className='row row-cols-1 row-cols-md-3 g-4'>
|
||||
{posts.map(post => (
|
||||
<article className='col' key={post.id}>
|
||||
<div className='card h-100 p-4'>
|
||||
<h2 className='h5'>
|
||||
<Link href={`/page/news/${post.id}`}><a>{post.title}</a></Link>
|
||||
</h2>
|
||||
<p>{newsSeo(post, post.id).description}</p>
|
||||
<Link href={`/page/news/${post.id}`}><a>مشاهده خبر</a></Link>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
{!isHome && (
|
||||
<div className='mt-4'>
|
||||
<h2 className='h5'>فایلهای معرفی بیمارستان</h2>
|
||||
<p><a download href='/take-stock.pdf'>دانلود دفترچه معرفی و فروش سهام عمومی بیمارستان مهر پرند</a></p>
|
||||
<p><a download href='/Explanatory_plan_of_Mehr_ranian_Parand_Hospital.pdf'>دانلود طرح توجیهی بیمارستان مهر پرند</a></p>
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
</section>
|
||||
)
|
||||
|
||||
return isHome ? content : <AppContainer>{content}</AppContainer>
|
||||
}
|
||||
|
||||
export async function getServerSideProps({ res }) {
|
||||
try {
|
||||
const { data } = await axios.get(AppUrl('news'), { timeout: 10000 })
|
||||
const posts = Array.isArray(data) ? data : data && data.data
|
||||
if (!Array.isArray(posts)) throw new Error('Unexpected news response')
|
||||
return { props: { data: posts } }
|
||||
} catch (error) {
|
||||
console.warn('News list: API unavailable:', error.message)
|
||||
res.statusCode = 503
|
||||
res.setHeader('Retry-After', '60')
|
||||
return { props: { data: [], unavailable: true } }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user