修复日期为空时编译错误的bug

This commit is contained in:
tlyong1992
2022-06-07 14:50:46 +08:00
parent 96a13170fd
commit a6948117f8
11 changed files with 23 additions and 23 deletions

View File

@@ -7,15 +7,15 @@ export const LayoutArchive = props => {
const postsSortByDate = Object.create(posts) const postsSortByDate = Object.create(posts)
postsSortByDate.sort((a, b) => { postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date.start_date || a.createdTime) const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date.start_date || b.createdTime) const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA return dateB - dateA
}) })
const archivePosts = {} const archivePosts = {}
postsSortByDate.forEach(post => { postsSortByDate.forEach(post => {
const date = post.date.start_date.slice(0, 7) const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) { if (archivePosts[date]) {
archivePosts[date].push(post) archivePosts[date].push(post)
} else { } else {
@@ -39,7 +39,7 @@ export const LayoutArchive = props => {
> >
<div id={post?.date?.start_date}> <div id={post?.date?.start_date}>
<span className="text-gray-400"> <span className="text-gray-400">
{post.date.start_date} {post.date?.start_date}
</span>{' '} </span>{' '}
&nbsp; &nbsp;
<Link <Link

View File

@@ -9,14 +9,14 @@ export const LayoutArchive = (props) => {
// 时间排序 // 时间排序
postsSortByDate.sort((a, b) => { postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date.start_date || a.createdTime) const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date.start_date || b.createdTime) const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA return dateB - dateA
}) })
const archivePosts = {} const archivePosts = {}
postsSortByDate.forEach(post => { postsSortByDate.forEach(post => {
const date = post.date.start_date.slice(0, 7) const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) { if (archivePosts[date]) {
archivePosts[date].push(post) archivePosts[date].push(post)
} else { } else {

View File

@@ -27,7 +27,7 @@ const BlogArchiveItem = ({ posts = [], archiveTitle }) => {
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
> >
<div id={post?.date?.start_date}> <div id={post?.date?.start_date}>
<span className="text-gray-400">{post.date.start_date}</span>{' '} <span className="text-gray-400">{post.date?.start_date}</span>{' '}
&nbsp; &nbsp;
<Link href={`${BLOG.SUB_PATH}/article/${post.slug}`} passHref> <Link href={`${BLOG.SUB_PATH}/article/${post.slug}`} passHref>
<a className="dark:text-gray-400 dark:hover:text-gray-300 overflow-x-hidden hover:underline cursor-pointer text-gray-600"> <a className="dark:text-gray-400 dark:hover:text-gray-300 overflow-x-hidden hover:underline cursor-pointer text-gray-600">

View File

@@ -10,15 +10,15 @@ export const LayoutArchive = (props) => {
// 时间排序 // 时间排序
postsSortByDate.sort((a, b) => { postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date.start_date || a.createdTime) const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date.start_date || b.createdTime) const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA return dateB - dateA
}) })
const archivePosts = {} const archivePosts = {}
postsSortByDate.forEach(post => { postsSortByDate.forEach(post => {
const date = post.date.start_date.slice(0, 7) const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) { if (archivePosts[date]) {
archivePosts[date].push(post) archivePosts[date].push(post)
} else { } else {

View File

@@ -27,7 +27,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => {
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-indigo-500 dark:hover:border-indigo-300 dark:border-indigo-400 transform duration-500" className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-indigo-500 dark:hover:border-indigo-300 dark:border-indigo-400 transform duration-500"
> >
<div id={post?.date?.start_date}> <div id={post?.date?.start_date}>
<span className="text-gray-400">{post.date.start_date}</span>{' '} <span className="text-gray-400">{post.date?.start_date}</span>{' '}
&nbsp; &nbsp;
<Link href={`${BLOG.SUB_PATH}/article/${post.slug}`} passHref> <Link href={`${BLOG.SUB_PATH}/article/${post.slug}`} passHref>
<a className="dark:text-gray-400 dark:hover:text-indigo-300 overflow-x-hidden hover:underline cursor-pointer text-gray-600"> <a className="dark:text-gray-400 dark:hover:text-indigo-300 overflow-x-hidden hover:underline cursor-pointer text-gray-600">

View File

@@ -33,7 +33,7 @@ const BlogPostCard = ({ post, showSummary }) => {
> >
<a className="font-light hover:underline cursor-pointer text-sm leading-4 mr-3"> <a className="font-light hover:underline cursor-pointer text-sm leading-4 mr-3">
<i className="far fa-calendar-alt mr-1" /> <i className="far fa-calendar-alt mr-1" />
{post.date.start_date} {post.date?.start_date}
</a> </a>
</Link> </Link>
</div> </div>

View File

@@ -7,15 +7,15 @@ export const LayoutArchive = props => {
const postsSortByDate = Object.create(posts) const postsSortByDate = Object.create(posts)
postsSortByDate.sort((a, b) => { postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date.start_date || a.createdTime) const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date.start_date || b.createdTime) const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA return dateB - dateA
}) })
const archivePosts = {} const archivePosts = {}
postsSortByDate.forEach(post => { postsSortByDate.forEach(post => {
const date = post.date.start_date.slice(0, 7) const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) { if (archivePosts[date]) {
archivePosts[date].push(post) archivePosts[date].push(post)
} else { } else {
@@ -41,7 +41,7 @@ export const LayoutArchive = props => {
> >
<div id={post?.date?.start_date}> <div id={post?.date?.start_date}>
<span className="text-gray-400"> <span className="text-gray-400">
{post.date.start_date} {post.date?.start_date}
</span>{' '} </span>{' '}
&nbsp; &nbsp;
<Link <Link

View File

@@ -31,7 +31,7 @@ const BlogPostCard = ({ post, showSummary }) => {
'flex mt-2 items-center justify-start flex-wrap space-x-3 text-gray-400' 'flex mt-2 items-center justify-start flex-wrap space-x-3 text-gray-400'
} }
> >
<div className="text-sm py-1">{post.date.start_date}</div> <div className="text-sm py-1">{post.date?.start_date}</div>
{CONFIG_MEDIUM.POST_LIST_CATEGORY && ( {CONFIG_MEDIUM.POST_LIST_CATEGORY && (
<CategoryItem category={post.category} /> <CategoryItem category={post.category} />
)} )}

View File

@@ -9,15 +9,15 @@ export const LayoutArchive = (props) => {
// 时间排序 // 时间排序
postsSortByDate.sort((a, b) => { postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date.start_date || a.createdTime) const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date.start_date || b.createdTime) const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA return dateB - dateA
}) })
const archivePosts = {} const archivePosts = {}
postsSortByDate.forEach(post => { postsSortByDate.forEach(post => {
const date = post.date.start_date.slice(0, 7) const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) { if (archivePosts[date]) {
archivePosts[date].push(post) archivePosts[date].push(post)
} else { } else {

View File

@@ -27,7 +27,7 @@ const BlogPostArchive = ({ posts = [], archiveTitle }) => {
className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500" className="border-l-2 p-1 text-xs md:text-base items-center hover:scale-x-105 hover:border-gray-500 dark:hover:border-gray-300 dark:border-gray-400 transform duration-500"
> >
<div id={post?.date?.start_date}> <div id={post?.date?.start_date}>
<span className="text-gray-400">{post.date.start_date}</span>{' '} <span className="text-gray-400">{post.date?.start_date}</span>{' '}
&nbsp; &nbsp;
<Link href={`${BLOG.SUB_PATH}/article/${post.slug}`} passHref> <Link href={`${BLOG.SUB_PATH}/article/${post.slug}`} passHref>
<a className="dark:text-gray-400 dark:hover:text-gray-300 overflow-x-hidden hover:underline cursor-pointer text-gray-600"> <a className="dark:text-gray-400 dark:hover:text-gray-300 overflow-x-hidden hover:underline cursor-pointer text-gray-600">

View File

@@ -48,7 +48,7 @@ const BlogPostCard = ({ post, showSummary }) => {
passHref passHref
> >
<a className="font-light hover:underline cursor-pointer text-sm leading-4 mr-3"> <a className="font-light hover:underline cursor-pointer text-sm leading-4 mr-3">
{post.date.start_date} {post.date?.start_date}
</a> </a>
</Link> </Link>
</div> </div>