From 4c5c47d71e841723a19883cfb0bcf5989e58c5ef Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 13 Feb 2023 18:48:20 +0800 Subject: [PATCH] custom table options --- lib/notion/getPageProperties.js | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index d698ea44..eb3428d0 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -61,7 +61,7 @@ export default async function getPageProperties(id, block, schema, authToken, ta } } - // 设置自定义字段 + // 映射键:用户自定义表头名 const fieldNames = BLOG.NOTION_PROPERTY_NAME if (fieldNames) { Object.keys(fieldNames).forEach(key => { @@ -73,24 +73,10 @@ export default async function getPageProperties(id, block, schema, authToken, ta properties.type = properties.type?.[0] properties.status = properties.status?.[0] - // 映射值:用户个性化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' - } + // 映射值:用户个性化type和status字段的下拉框选项,在此映射回代码的英文标识 + mapProperties(properties) - if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_post) { + if (properties.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) @@ -139,3 +125,21 @@ function getImageUrl(imgObj, blockVal) { // 其他图片链接 或 emoji return imgObj } + +function mapProperties(properties) { + 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' + } +}