From d3255ae6253ee15cfa550cc438014d680f6962d8 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 13 Feb 2023 18:29:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E5=AD=97=E6=AE=B5=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.config.js | 9 +++++++-- lib/notion/getPageProperties.js | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/blog.config.js b/blog.config.js index 5f1ec119..89916735 100644 --- a/blog.config.js +++ b/blog.config.js @@ -194,9 +194,14 @@ const BLOG = { // 自定义配置notion数据库字段名 NOTION_PROPERTY_NAME: { password: process.env.NEXT_PUBLIC_NOTION_PROPERTY_PASSWORD || 'password', - type: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TYPE || 'type', - title: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TITLE || 'title', + type: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TYPE || 'type', // 文章类型, + type_post: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TYPE_POST || 'Post', // 当type文章类型与此值相同时,为博文。 + type_page: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TYPE_PAGE || 'Page', // 当type文章类型与此值相同时,为单页。 + type_notice: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TYPE_NOTICE || 'Notice', // 当type文章类型与此值相同时,为公告。 + title: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TITLE || 'title', // 文章标题 status: process.env.NEXT_PUBLIC_NOTION_PROPERTY_STATUS || 'status', + status_publish: process.env.NEXT_PUBLIC_NOTION_PROPERTY_STATUS_PUBLISH || 'Published', // 当status状态值与此相同时为发布,可以为中文 + status_invisible: process.env.NEXT_PUBLIC_NOTION_PROPERTY_STATUS_INVISIBLE || 'Invisible', // 当status状态值与此相同时为隐藏发布,可以为中文 , 除此之外其他页面状态不会显示在博客上 summary: process.env.NEXT_PUBLIC_NOTION_PROPERTY_SUMMARY || 'summary', slug: process.env.NEXT_PUBLIC_NOTION_PROPERTY_SLUG || 'slug', category: process.env.NEXT_PUBLIC_NOTION_PROPERTY_CATEGORY || 'category', diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index b498fd82..d698ea44 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -69,10 +69,28 @@ export default async function getPageProperties(id, block, schema, authToken, ta }) } + // type\status是下拉选框 取数组第一个 properties.type = properties.type?.[0] properties.status = properties.status?.[0] - if (properties.type === 'Post') { + // 映射值:用户个性化type和status字段后,在此映射回代码的英文标识 + if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_post) { + properties.type = 'Post' + } + if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_page) { + properties.type = 'Page' + } + if (properties?.type === BLOG.NOTION_PROPERTY_NAME.type_notice) { + properties.type = 'Notice' + } + if (properties?.status === BLOG.NOTION_PROPERTY_NAME.status_publish) { + properties.status = 'Published' + } + if (properties?.status === BLOG.NOTION_PROPERTY_NAME.status_invisible) { + properties.status = 'Invisible' + } + + if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_post) { properties.slug = BLOG.POST_URL_PREFIX ? (BLOG.POST_URL_PREFIX + '/' + (properties.slug ?? properties.id)) : (properties.slug ?? properties.id) } else { properties.slug = (properties.slug ?? properties.id)