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