fix: 修复日期显示NaN年NaN月NaN日的问题
- formatDate兼容date和createdAt两种字段名 - 增加空值和无效日期防御 - 同步news.json分类数据(之前category全为null) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
这个提交包含在:
父节点
ab49633b81
当前提交
6c79aad1dd
@ -14,7 +14,7 @@
|
||||
<!-- 文章元信息 -->
|
||||
<div class="article-meta">
|
||||
<span class="article-category">{{ article.category }}</span>
|
||||
<span class="article-date">{{ formatDate(article.date) }}</span>
|
||||
<span class="article-date">{{ formatDate(article.date || article.createdAt) }}</span>
|
||||
<span class="article-author">作者:{{ article.author }}</span>
|
||||
</div>
|
||||
|
||||
@ -230,7 +230,9 @@ const nextArticle = computed(() => currentIndex.value < allArticles.value.length
|
||||
const otherArticles = allArticles
|
||||
|
||||
function formatDate(dateStr) {
|
||||
const d = new Date(dateStr)
|
||||
if (!dateStr) return ''
|
||||
const d = new Date(dateStr.includes('T') ? dateStr : dateStr + 'T00:00:00')
|
||||
if (isNaN(d.getTime())) return ''
|
||||
return `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日`
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
</div>
|
||||
<div class="blog-card__body">
|
||||
<div class="blog-card__meta">
|
||||
<span class="blog-card__date">{{ formatDate(article.date) }}</span>
|
||||
<span class="blog-card__date">{{ formatDate(article.date || article.createdAt) }}</span>
|
||||
<span class="blog-card__author">{{ article.author }}</span>
|
||||
</div>
|
||||
<h2 class="blog-card__title">{{ article.title }}</h2>
|
||||
@ -136,7 +136,9 @@ function getCategoryCount(key) {
|
||||
}
|
||||
|
||||
function formatDate(dateStr) {
|
||||
const d = new Date(dateStr)
|
||||
if (!dateStr) return ''
|
||||
const d = new Date(dateStr.includes('T') ? dateStr : dateStr + 'T00:00:00')
|
||||
if (isNaN(d.getTime())) return ''
|
||||
return `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日`
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
>
|
||||
<div class="news-meta">
|
||||
<span :class="['news-cat', `news-cat--${article.category}`]">{{ article.category }}</span>
|
||||
<time class="news-date" :datetime="article.date">{{ formatDate(article.date) }}</time>
|
||||
<time class="news-date" :datetime="article.date || article.createdAt">{{ formatDate(article.date || article.createdAt) }}</time>
|
||||
</div>
|
||||
<h2 class="news-title">{{ article.title }}</h2>
|
||||
<p class="news-summary">{{ article.summary }}</p>
|
||||
@ -87,8 +87,8 @@ useBreadcrumbSchema([
|
||||
headline: article.title,
|
||||
description: article.summary,
|
||||
articleBody: article.content,
|
||||
datePublished: article.date + 'T00:00:00+08:00',
|
||||
dateModified: article.date + 'T00:00:00+08:00',
|
||||
datePublished: (article.date || article.createdAt) + 'T00:00:00+08:00',
|
||||
dateModified: (article.date || article.createdAt) + 'T00:00:00+08:00',
|
||||
articleSection: article.category,
|
||||
inLanguage: 'zh-CN',
|
||||
url: 'https://1814.love/news',
|
||||
@ -110,7 +110,9 @@ const filteredArticles = computed(() => {
|
||||
})
|
||||
|
||||
function formatDate(dateStr) {
|
||||
const d = new Date(dateStr)
|
||||
if (!dateStr) return ''
|
||||
const d = new Date(dateStr.includes('T') ? dateStr : dateStr + 'T00:00:00')
|
||||
if (isNaN(d.getTime())) return ''
|
||||
return `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日`
|
||||
}
|
||||
</script>
|
||||
|
||||
正在加载...
x
在新工单中引用
屏蔽一个用户