fix: seo friendly
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
} from 'mdb-react-ui-kit'
|
||||
import Image from 'next/image'
|
||||
import { AppFile, AppUrl } from '../../../lib/api'
|
||||
import { newsSeo } from '../../../lib/seo'
|
||||
import { Tag, TagLabel, HStack } from '@chakra-ui/react'
|
||||
|
||||
const moment = require('moment-jalaali')
|
||||
@@ -40,7 +41,7 @@ const News = ({ post }) => {
|
||||
loader={Parallax}
|
||||
src='Parallax.png'
|
||||
className={'responsive-img shadow-5'}
|
||||
alt='Picture of the author'
|
||||
alt={post.title}
|
||||
width={2050}
|
||||
height={1050}
|
||||
priority
|
||||
@@ -175,11 +176,14 @@ const News = ({ post }) => {
|
||||
export default News
|
||||
|
||||
export const getServerSideProps = async context => {
|
||||
const { query } = context
|
||||
const posData = await axios.get(AppUrl(`news/${query.slug}`))
|
||||
const post = await posData.data
|
||||
|
||||
return {
|
||||
props: { post, fallback: false } // will be passed to the page component as props
|
||||
const { slug } = context.params
|
||||
try {
|
||||
const { data: post } = await axios.get(AppUrl(`news/${encodeURIComponent(slug)}`), { timeout: 10000 })
|
||||
if (!post || !post.title || typeof post.text !== 'string') return { notFound: true }
|
||||
return { props: { post, seo: newsSeo(post, slug) } }
|
||||
} catch (error) {
|
||||
if (error.response && error.response.status === 404) return { notFound: true }
|
||||
// Temporary upstream failures must stay 5xx rather than removing real articles from search.
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user