From 6c79aad1dd886869694ea88b9d72b59ad54f05d4 Mon Sep 17 00:00:00 2001 From: wx <2636507191@qq.com> Date: Mon, 13 Apr 2026 14:22:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E6=98=BE=E7=A4=BANaN=E5=B9=B4NaN=E6=9C=88NaN=E6=97=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - formatDate兼容date和createdAt两种字段名 - 增加空值和无效日期防御 - 同步news.json分类数据(之前category全为null) Co-Authored-By: Claude Opus 4.6 (1M context) --- pages/blog/[id].vue | 6 ++++-- pages/blog/index.vue | 6 ++++-- pages/news.vue | 10 ++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pages/blog/[id].vue b/pages/blog/[id].vue index 38c9c2f..9d4312a 100644 --- a/pages/blog/[id].vue +++ b/pages/blog/[id].vue @@ -14,7 +14,7 @@
- +
@@ -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()}日` } diff --git a/pages/blog/index.vue b/pages/blog/index.vue index d110b56..a3d79af 100644 --- a/pages/blog/index.vue +++ b/pages/blog/index.vue @@ -51,7 +51,7 @@
- {{ formatDate(article.date) }} + {{ formatDate(article.date || article.createdAt) }} {{ article.author }}

{{ article.title }}

@@ -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()}日` } diff --git a/pages/news.vue b/pages/news.vue index 68bab9e..d3a89af 100644 --- a/pages/news.vue +++ b/pages/news.vue @@ -40,7 +40,7 @@ >
{{ article.category }} - +

{{ article.title }}

{{ article.summary }}

@@ -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()}日` }