From 1f255c57459786106bf5313cc538696cba132cea Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Tue, 8 Oct 2024 18:36:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8F=9C=E5=8D=95=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=90=8D=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/db/getSiteData.js | 7 +++---- lib/notion/getPageProperties.js | 27 ++++++++++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/db/getSiteData.js b/lib/db/getSiteData.js index f27f30a5610..951bdaac00b 100755 --- a/lib/db/getSiteData.js +++ b/lib/db/getSiteData.js @@ -275,16 +275,15 @@ function getCustomMenu({ collectionData, NOTION_CONFIG }) { const menuPages = collectionData.filter( post => post.status === 'Published' && - (post?.type === BLOG.NOTION_PROPERTY_NAME.type_menu || - post?.type === BLOG.NOTION_PROPERTY_NAME.type_sub_menu) + (post?.type === 'Menu' || post?.type === 'SubMenu') ) const menus = [] if (menuPages && menuPages.length > 0) { menuPages.forEach(e => { e.show = true - if (e.type === BLOG.NOTION_PROPERTY_NAME.type_menu) { + if (e.type === 'Menu') { menus.push(e) - } else if (e.type === BLOG.NOTION_PROPERTY_NAME.type_sub_menu) { + } else if (e.type === 'SubMenu') { const parentMenu = menus[menus.length - 1] if (parentMenu) { if (parentMenu.subMenus) { diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index a946164b9fc..d62568cd2c2 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -149,20 +149,25 @@ function convertToJSON(str) { * 映射用户自定义表头 */ function mapProperties(properties) { - if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_post) { - properties.type = 'Post' + const typeMap = { + [BLOG.NOTION_PROPERTY_NAME.type_post]: 'Post', + [BLOG.NOTION_PROPERTY_NAME.type_page]: 'Page', + [BLOG.NOTION_PROPERTY_NAME.type_notice]: 'Notice', + [BLOG.NOTION_PROPERTY_NAME.type_menu]: 'Menu', + [BLOG.NOTION_PROPERTY_NAME.type_sub_menu]: 'SubMenu' } - if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_page) { - properties.type = 'Page' - } - if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_notice) { - properties.type = 'Notice' + + const statusMap = { + [BLOG.NOTION_PROPERTY_NAME.status_publish]: 'Published', + [BLOG.NOTION_PROPERTY_NAME.status_invisible]: 'Invisible' } - if (properties?.status === BLOG.NOTION_PROPERTY_NAME.status_publish) { - properties.status = 'Published' + + if (properties?.type && typeMap[properties.type]) { + properties.type = typeMap[properties.type] } - if (properties?.status === BLOG.NOTION_PROPERTY_NAME.status_invisible) { - properties.status = 'Invisible' + + if (properties?.status && statusMap[properties.status]) { + properties.status = statusMap[properties.status] } }