diff --git a/.env.local b/.env.local index 9770227a..6c7c4fca 100644 --- a/.env.local +++ b/.env.local @@ -1,2 +1,2 @@ # 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables -NEXT_PUBLIC_VERSION=3.10.1 +NEXT_PUBLIC_VERSION=3.10.2 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/lang/en-US.js b/lib/lang/en-US.js index b5438cde..10ac5bf9 100644 --- a/lib/lang/en-US.js +++ b/lib/lang/en-US.js @@ -38,7 +38,8 @@ export default { RECENT_COMMENTS: 'Recent Comments', DEBUG_OPEN: 'Debug', DEBUG_CLOSE: 'Close', - THEME_SWITCH: 'Theme Switch' + THEME_SWITCH: 'Theme Switch', + ANNOUNCEMENT: 'Announcement' }, PAGINATION: { PREV: 'Prev', diff --git a/lib/lang/zh-CN.js b/lib/lang/zh-CN.js index 1ba84f91..1dddddb9 100644 --- a/lib/lang/zh-CN.js +++ b/lib/lang/zh-CN.js @@ -40,7 +40,8 @@ export default { RECENT_COMMENTS: '最新评论', DEBUG_OPEN: '开启调试', DEBUG_CLOSE: '关闭调试', - THEME_SWITCH: '切换主题' + THEME_SWITCH: '切换主题', + ANNOUNCEMENT: '公告' }, PAGINATION: { PREV: '上一页', diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index b498fd82..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 => { @@ -69,9 +69,13 @@ export default async function getPageProperties(id, block, schema, authToken, ta }) } + // type\status是下拉选框 取数组第一个 properties.type = properties.type?.[0] properties.status = properties.status?.[0] + // 映射值:用户个性化type和status字段的下拉框选项,在此映射回代码的英文标识 + mapProperties(properties) + if (properties.type === 'Post') { properties.slug = BLOG.POST_URL_PREFIX ? (BLOG.POST_URL_PREFIX + '/' + (properties.slug ?? properties.id)) : (properties.slug ?? properties.id) } else { @@ -121,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' + } +} diff --git a/package.json b/package.json index f30999c6..c9cb101e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-next", - "version": "3.10.1", + "version": "3.10.2", "homepage": "https://github.com/tangly1024/NotionNext.git", "license": "MIT", "repository": { diff --git a/themes/example/components/Announcement.js b/themes/example/components/Announcement.js index 01ec60c3..07e3556c 100644 --- a/themes/example/components/Announcement.js +++ b/themes/example/components/Announcement.js @@ -1,16 +1,18 @@ +import { useGlobal } from '@/lib/global' import dynamic from 'next/dynamic' const NotionPage = dynamic(() => import('@/components/NotionPage')) const Announcement = ({ post, className }) => { + const { locale } = useGlobal() if (!post) { return <> } return