From 97266b130f1b87fbf1ce499e9ba38160636da626 Mon Sep 17 00:00:00 2001 From: tangly Date: Mon, 6 Dec 2021 20:39:26 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E9=80=82=E9=85=8D=E6=97=A0=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/TagItem.js | 5 +++++ lib/cache/cache_manager.js | 2 +- lib/global.js | 1 - lib/lang/en-US.js | 1 + lib/lang/zh-CN.js | 1 + lib/notion/getAllPosts.js | 8 +++----- lib/notion/getAllTags.js | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/components/TagItem.js b/components/TagItem.js index efd322fd..c9d6a4a7 100644 --- a/components/TagItem.js +++ b/components/TagItem.js @@ -2,8 +2,13 @@ import { faTag } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import Link from 'next/link' import React from 'react' +import { useGlobal } from '@/lib/global' const TagItem = ({ tag, selected }) => { + const { locale } = useGlobal() + if (!tag) { + <>{locale.COMMON.NOTAG} + } return (
  • { return { name: tag, color: tagOptions.find(t => t.value === tag).color } }) || ['默认'] properties.createdTime = new Date(pageBlock[id].value?.created_time).toString() properties.lastEditedTime = new Date(pageBlock[id].value?.last_edited_time).toString() properties.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false properties.page_cover = getPostCover(id, pageBlock) ?? BLOG.defaultImgCover properties.content = pageBlock[id].value?.content ?? [] - properties.tagItems = tagItems + properties.tagItems = properties?.tags?.map(tag => { + return { name: tag, color: tagOptions.find(t => t.value === tag)?.color || 'gray' } + }) || [] data.push(properties) } diff --git a/lib/notion/getAllTags.js b/lib/notion/getAllTags.js index 96af611c..1fe5523f 100644 --- a/lib/notion/getAllTags.js +++ b/lib/notion/getAllTags.js @@ -26,7 +26,7 @@ export async function getAllTags ({ allPosts, sliceCount = 12, tagOptions }) { // 按照标签数量排序 const list = Object.keys(tagObj).map((tag) => { - const color = tagOptions.find(option => option.value === tag).color + const color = tagOptions.find(option => option.value === tag)?.color || 'gray' return { name: tag, count: tagObj[tag], color } }) list.sort((a, b) => b.count - a.count)