diff --git a/README.md b/README.md index 99a7195..148d388 100644 --- a/README.md +++ b/README.md @@ -13,19 +13,28 @@ Thanks to the [original author](https://github.com/EasyChris/obsidian-to-notion) Thus, based on the [original author's work](https://github.com/EasyChris/obsidian-to-notion), I've added a feature to match the [NotionNext](https://github.com/tangly1024/NotionNext) template. This way, you can edit directly in Obsidian and publish with a single click after organizing. -**Now, support both NotionNext and General databases.** +**Now, support both NotionNext and General databases with customised properties.** -**现在支持NotionNext和普通Notion数据库。** +**现在支持NotionNext和普通Notion数据库,可自定义数据库列表。** ## TODO List -- [ ] Support custom properties for Notion General database. 支持自定义属性 +- [x] Support custom properties for Notion General database. 支持自定义属性 - [ ] Support group upload with one click 支持一键多数据库上传 - [x] Support preview for database details in plugin settings. 支持预览数据库详情 - [x] Support edit for database details in plugin settings. 支持编辑数据库详情 ## Update +### 2.2.0 + +- add the support for custom properties in the Notion General database. 支持自定义属性 + +![](https://minioapi.pjx.ac.cn/img1/2024/01/039760ee966c6c1e04410d3f69787f85.png) +- Once you create the properties, you can preview the database details in the plugin settings. + +Once you add the custom properties in the Notion General database, you can add the corresponding properties in the YAML frontmatter. **The name of the properties is case sensitive. You should use small letter.** + ### 2.1.0 - add confirmation interface for deleting a database 增加删除数据库的确认界面 diff --git a/src/upload/updateYaml.ts b/src/upload/updateYaml.ts index 2a91687..219254d 100644 --- a/src/upload/updateYaml.ts +++ b/src/upload/updateYaml.ts @@ -1,6 +1,6 @@ import { App, Notice, TFile } from "obsidian"; import ObsidianSyncNotionPlugin from "../main"; -import {DatabaseDetails, PluginSettings} from "../ui/settingTabs"; +import {DatabaseDetails} from "../ui/settingTabs"; export async function updateYamlInfo( yamlContent: string, diff --git a/src/upload/upload_general/Upload2NotionGeneral.ts b/src/upload/upload_general/Upload2NotionGeneral.ts index b0cb5af..266f666 100644 --- a/src/upload/upload_general/Upload2NotionGeneral.ts +++ b/src/upload/upload_general/Upload2NotionGeneral.ts @@ -139,7 +139,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral { const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter; const {abName} = this.dbDetails - const notionIDKey = `${abName}-NotionID`; + const notionIDKey = `NotionID-${abName}`; const notionID = frontmasster ? frontmasster[notionIDKey] : null; diff --git a/src/upload/upload_next/Upload2NotionNext.ts b/src/upload/upload_next/Upload2NotionNext.ts index 9408b70..bba434f 100644 --- a/src/upload/upload_next/Upload2NotionNext.ts +++ b/src/upload/upload_next/Upload2NotionNext.ts @@ -228,7 +228,7 @@ export class Upload2NotionNext extends UploadBaseNext { const file2Block = markdownToBlocks(__content, options); const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter const {abName} = this.dbDetails - const notionIDKey = `${abName}-NotionID`; + const notionIDKey = `NotionID-${abName}`; const notionID = frontmasster ? frontmasster[notionIDKey] : null; diff --git a/src/upload/upoload_custom/Upload2NotionCustom.ts b/src/upload/upoload_custom/Upload2NotionCustom.ts index 3f73bf6..5e6b6fc 100644 --- a/src/upload/upoload_custom/Upload2NotionCustom.ts +++ b/src/upload/upoload_custom/Upload2NotionCustom.ts @@ -107,7 +107,9 @@ export class Upload2NotionCustom extends UploadBaseCustom { const file2Block = markdownToBlocks(__content, options); const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter; - const notionID = frontmasster ? frontmasster.notionID : null; + const {abName} = this.dbDetails + const notionIDKey = `NotionID-${abName}`; + const notionID = frontmasster ? frontmasster[notionIDKey] : null; if (notionID) { res = await this.updatePage( diff --git a/src/upload/upoload_custom/getMarkdownCustom.ts b/src/upload/upoload_custom/getMarkdownCustom.ts index 0dacc09..ed33655 100644 --- a/src/upload/upoload_custom/getMarkdownCustom.ts +++ b/src/upload/upoload_custom/getMarkdownCustom.ts @@ -1,13 +1,12 @@ -import {App, Notice, TAbstractFile, TFile} from "obsidian"; +import {App, Notice} from "obsidian"; import {i18nConfig} from "../../lang/I18n"; -import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs"; +import {DatabaseDetails} from "../../ui/settingTabs"; export async function getNowFileMarkdownContentCustom( - app: App, + app: App, dbDetails: DatabaseDetails, - settings: PluginSettings, ) { - const nowFile = app.workspace.getActiveFile(); + const nowFile = app.workspace.getActiveFile(); if (!nowFile) { new Notice(i18nConfig["open-file"]); return; @@ -15,36 +14,44 @@ export async function getNowFileMarkdownContentCustom( let cover = ''; let customValues: Record = {}; - const FileCache = app.metadataCache.getFileCache(nowFile); - try { - cover = FileCache.frontmatter.coverurl; + const FileCache = app.metadataCache.getFileCache(nowFile); + try { + cover = FileCache.frontmatter.coverurl; - // Get custom property names from dbDetails - const customPropertyValues = dbDetails.customProperties.map(property => property.customName); + // Get custom property names from dbDetails excluding the title type property + const customPropertyNames = dbDetails.customProperties + .filter(property => property.customType !== 'title') // Exclude 'title' type property + .map(property => property.customName); - // Extract custom values from the frontmatter based on the names - customPropertyValues.forEach( propertyName => { - if (FileCache.frontmatter[propertyName] !== undefined) { + // Extract custom values from the front matter based on the names + customPropertyNames.forEach(propertyName => { + if (FileCache.frontmatter && FileCache.frontmatter[propertyName] !== undefined) { customValues[propertyName] = FileCache.frontmatter[propertyName]; } }); - customValues['title'] = nowFile.basename; // Use 'basename' for the file name without extension + // Check if any of the customProperties has a customType of 'title' + const titleProperty = dbDetails.customProperties.find(property => property.customType === 'title'); - } catch (error) { - new Notice(i18nConfig["set-tags-fail"]); - } + // If a 'title' type property exists, use the file's basename as its value + if (titleProperty) { + customValues[titleProperty.customName] = nowFile.basename; // Use 'basename' for the file name without extension + } - if (nowFile) { - const markDownData = await nowFile.vault.read(nowFile); - return { - markDownData, - nowFile, - cover, - customValues, - }; - } else { - new Notice(i18nConfig["open-file"]); - return; - } + } catch (error) { + new Notice(i18nConfig["set-tags-fail"]); + } + + if (nowFile) { + const markDownData = await nowFile.vault.read(nowFile); + return { + markDownData, + nowFile, + cover, + customValues, + }; + } else { + new Notice(i18nConfig["open-file"]); + return; + } }