fix post?.

This commit is contained in:
tangly1024.com
2023-07-11 18:28:16 +08:00
parent 47b3fa28e9
commit bb6b2b3e1d
10 changed files with 14 additions and 18 deletions

View File

@@ -96,7 +96,7 @@ export default function ArticleDetail(props) {
</article>
{post.type === 'Post' && <ArticleAround prev={prev} next={next} /> }
{post?.type === 'Post' && <ArticleAround prev={prev} next={next} /> }
{/* 评论互动 */}
<div className="duration-200 shadow py-6 px-12 w-screen md:w-full overflow-x-auto dark:border-gray-700 bg-white dark:bg-hexo-black-gray">

View File

@@ -227,7 +227,7 @@ const LayoutSlug = props => {
{/* 分享 */}
<ShareBar post={post} />
{post.type === 'Post' && <>
{post?.type === 'Post' && <>
<ArticleCopyright {...props} />
<ArticleRecommend {...props} />
<ArticleAdjacent {...props} />

View File

@@ -20,7 +20,7 @@ const BlogPostListScroll = ({ posts = [], currentSearch }) => {
const searchKey = getSearchKey()
if (searchKey) {
filteredPosts = posts.filter(post => {
const tagContent = post.tags ? post.tags.join(' ') : ''
const tagContent = post?.tags ? post?.tags.join(' ') : ''
const searchContent = post.title + post.summary + tagContent
return searchContent.toLowerCase().includes(searchKey.toLowerCase())
})

View File

@@ -174,7 +174,7 @@ const LayoutSlug = props => {
</div>
</div>
{/* 上一篇下一篇文章 */}
{post.type === 'Post' && <ArticleAround prev={prev} next={next} />}
{post?.type === 'Post' && <ArticleAround prev={prev} next={next} />}
{/* 评论区 */}
<Comment frontMatter={post} />
</section>

View File

@@ -87,10 +87,10 @@ export default function ArticleDetail(props) {
<ShareBar post={post} />
{/* 版权声明 */}
{post.type === 'Post' && <ArticleCopyright author={BLOG.AUTHOR} url={url} />}
{post?.type === 'Post' && <ArticleCopyright author={BLOG.AUTHOR} url={url} />}
{/* 推荐文章 */}
{post.type === 'Post' && <RecommendPosts currentPost={post} recommendPosts={recommendPosts} />}
{post?.type === 'Post' && <RecommendPosts currentPost={post} recommendPosts={recommendPosts} />}
<section className="flex justify-between">
{/* 分类 */}
@@ -104,7 +104,7 @@ export default function ArticleDetail(props) {
</>}
{/* 标签列表 */}
{post.type === 'Post' && (
{post?.type === 'Post' && (
<>
{post.tagItems && (
<div className="flex flex-nowrap leading-8 p-1 py-4 overflow-x-auto">
@@ -119,7 +119,7 @@ export default function ArticleDetail(props) {
</>
)}
</section>
{post.type === 'Post' && <BlogAround prev={prev} next={next} />}
{post?.type === 'Post' && <BlogAround prev={prev} next={next} />}
</>}
{/* 评论互动 */}

View File

@@ -34,7 +34,7 @@ export const ArticleInfo = (props) => {
<div className="mr-2 mb-4 md:ml-0">
{post?.publishTime}
</div>
{post.tags && (
{post?.tags && (
<div className="flex flex-nowrap max-w-full overflow-x-auto article-tags">
{post?.tags.map(tag => (
<TagItem key={tag} tag={tag} />

View File

@@ -110,7 +110,7 @@ const LayoutPostList = props => {
let filteredBlogPosts = []
if (filterKey && posts) {
filteredBlogPosts = posts.filter(post => {
const tagContent = post.tags ? post.tags.join(' ') : ''
const tagContent = post?.tags ? post?.tags.join(' ') : ''
const searchContent = post.title + post.summary + tagContent
return searchContent.toLowerCase().includes(filterKey.toLowerCase())
})

View File

@@ -1,5 +1,4 @@
import formatDate from '@/lib/formatDate'
import Image from 'next/image'
import BLOG from '@/blog.config'
import TagItem from './TagItem'
@@ -33,12 +32,9 @@ export const ArticleInfo = (props) => {
<span className="block">&nbsp;/&nbsp;</span>
</div>
<div className="mr-2 mb-4 md:ml-0">
{formatDate(
post?.publishTime || post?.createdTime,
BLOG.LANG
)}
{post?.publishTime}
</div>
{post.tags && (
{post?.tags && (
<div className="flex flex-nowrap max-w-full overflow-x-auto article-tags">
{post?.tags.map(tag => (
<TagItem key={tag} tag={tag} />

View File

@@ -21,7 +21,7 @@ export const ArticleInfo = (props) => {
<span> <i className="fa-regular fa-user"></i> <a href={CONFIG.AUTHOR_LINK}>{BLOG.AUTHOR}</a></span>
<span> - <i className="fa-regular fa-clock"></i> {post?.publishTime}</span>
{post?.category && <span> - <i className="fa-regular fa-folder"></i> <a href={`/category/${post?.category}`} className="hover:text-red-400 transition-all duration-200">{post?.category}</a></span>}
{post?.tags && post.tags?.length > 0 && post?.tags.map(t => <span key={t}> / <Link href={`/tag/${t}`}><span className=' hover:text-red-400 transition-all duration-200'>{t}</span></Link></span>)}
{post?.tags && post?.tags?.length > 0 && post?.tags.map(t => <span key={t}> / <Link href={`/tag/${t}`}><span className=' hover:text-red-400 transition-all duration-200'>{t}</span></Link></span>)}
</div>
</>)}

View File

@@ -32,7 +32,7 @@ export const BlogItem = props => {
<div>
{post.category && <Link href={`/category/${post.category}`} className='p-1'> <span className="hover:text-red-400 transition-all duration-200"><i className="fa-regular fa-folder mr-0.5"/>{post.category}</span></Link>}
{post.tags && post.tags?.length > 0 && post.tags.map(t => <Link key={t} href={`/tag/${t}`} className=' hover:text-red-400 transition-all duration-200'><span > /{t}</span></Link>)}
{post?.tags && post?.tags?.length > 0 && post?.tags.map(t => <Link key={t} href={`/tag/${t}`} className=' hover:text-red-400 transition-all duration-200'><span > /{t}</span></Link>)}
</div>
</div>