fix: 修复日期显示NaN年NaN月NaN日的问题

- formatDate兼容date和createdAt两种字段名
- 增加空值和无效日期防御
- 同步news.json分类数据(之前category全为null)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
这个提交包含在:
wx
2026-04-13 14:30:08 +08:00
提交者 wx
共同撰写人 Claude Opus 4.6
父节点 ab49633b81
当前提交 6c79aad1dd
共修改 3 个文件,包含 14 行新增和 8 行删除
+4 -2
查看文件
@@ -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>
+4 -2
查看文件
@@ -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>