Skip to content

Commit

Permalink
feat: 在config中可自定义修改Notion数据库属性名
Browse files Browse the repository at this point in the history
  • Loading branch information
JensonMiao committed Sep 9, 2022
1 parent 84d2ad2 commit 0bb0307
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1,2 1,2 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
NEXT_PUBLIC_VERSION=3.4.3
NEXT_PUBLIC_VERSION=3.4.3
13 changes: 13 additions & 0 deletions blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 129,19 @@ const BLOG = {
ADSENSE_GOOGLE_ID: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_ID || '', // 谷歌广告ID e.g ca-pub-xxxxxxxxxxxxxxxx

// 无关紧要的配置
// 自定义配置notion数据库字段名
NOTION_PROPERTY_NAME: {
password: 'password',
type: 'type',
title: 'title',
status: 'status',
summary: 'summary',
slug: 'slug',
category: 'category',
date: 'date',
tags: 'tags',
icon: 'icon'
},
AVATAR: '/avatar.png', // 作者头像,被notion中的ICON覆盖。如果没有ICON则取public目录下的avatar.png
TITLE: process.env.NEXT_PUBLIC_TITLE || 'NotionNext BLOG', // 站点标题 ,被notion中的页面标题覆盖
DESCRIPTION:
Expand Down
8 changes: 7 additions & 1 deletion lib/notion/getPageProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 58,13 @@ async function getPageProperties(id, block, schema, authToken, tagOptions, siteI
}
}
}

// 设置自定义字段
const fieldNames = BLOG.NOTION_PROPERTY_NAME
if (fieldNames) {
Object.keys(fieldNames).forEach(key => {
if (fieldNames[key] && properties[fieldNames[key]]) properties[key] = properties[fieldNames[key]]
})
}
properties.slug = properties.slug ?? properties.id
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG)
Expand Down

0 comments on commit 0bb0307

Please sign in to comment.