reformat code and update readme file

This commit is contained in:
Jiaxin Peng
2024-07-04 20:51:07 +01:00
parent bfde5dfe1a
commit 9c93e38aff
20 changed files with 352 additions and 511 deletions

View File

@@ -1,5 +1,25 @@
- Update NotionNext function that ## Fix
- `tags`, `titleicon`, `slug` and `summary` are now optional. You can remove them from the frontmatter if you don't need them. - fixed the issue that you cannot have empty values in the front matter of the customised database.
- 修复了自定义数据库的前置数据中不能有空值的问题。
For example, you have the property `tag` in your customised database, and you do not want to sync `tag` to Notion. You can remove the `tag` from the front matter.
- 例如,自定义数据库中有属性`tag`,但是你不想将`tag`同步到Notion。现在你可以直接在frontmatter中删除`tag`
- 更新 NotionNext 同步功能
- `tags`, `titleicon`, `slug``summary` 现在不是必选项了。你可以从你的模板中删除这些字段。 ## Improvement
**⚠️⚠️⚠️: The exist customised database should be recreated if you want to update to version 2.3.0. The new version has a new database structure, and the old database structure is not compatible with the new version to build the index properly.**
### 自定义数据库用户
**⚠️⚠️⚠️: 如果你想要更新到2.3.0版本,你需要重新创建自定义数据库。新版本有一个新的数据库结构,旧的数据库结构无法构建索引。**
- redesigned the way to create new customised database. The modal has been removed with a more straightforward layout.
- 重新设计了自定义数据库的创建方式。已删除模态框,采用更直观的布局。
![](https://minioapi.pjx.ac.cn/img1/2024/07/7a1550aefd71175c981077ce46d03c87.png)
- improved the edit modal for customised database. The layout has been simplified and the form has been reorganized.
- 改进了自定义数据库的编辑模态框。简化了布局,重新组织了表单。
![](https://minioapi.pjx.ac.cn/img1/2024/07/471ea519b7cb3fba8f0b57956bb1f973.png)
- improved the preview modal for customised database.
- 改进了自定义数据库的预览模态框。
![](https://minioapi.pjx.ac.cn/img1/2024/07/9599d77116afad065d2e31129942acc7.png)

201
README.md
View File

@@ -8,7 +8,7 @@
[//]: # ([![Github all releases](https://img.shields.io/github/downloads/jxpeng98/obsidian-to-NotionNext/total.svg)](https://GitHub.com/jxpeng98/obsidian-to-NotionNext/releases/)) [//]: # ([![Github all releases](https://img.shields.io/github/downloads/jxpeng98/obsidian-to-NotionNext/total.svg)](https://GitHub.com/jxpeng98/obsidian-to-NotionNext/releases/))
[中文文档](README-zh.md) [//]: # ([中文文档](README-zh.md))
**Now, support both NotionNext and General databases with customised properties.** **Now, support both NotionNext and General databases with customised properties.**
@@ -16,11 +16,18 @@
## TODO List ## TODO List
- [ ] Modify the Edit function for the custom properties. 改进自定义属性的编辑功能 - [x] ~~Modify the Edit function for the custom properties. 改进自定义属性的编辑功能~~
- [ ] Support group upload with one click 支持一键多数据库上传 - [ ] Support group upload with one click 支持一键多数据库上传
- [x] Support custom properties for Notion General database. 支持自定义属性 - [x] ~~Support custom properties for Notion General database. 支持自定义属性~~
- [x] Support preview for database details in plugin settings. 支持预览数据库详情 - [x] ~~Support preview for database details in plugin settings. 支持预览数据库详情~~
- [x] Support edit for database details in plugin settings. 支持编辑数据库详情 - [x] ~~Support edit for database details in plugin settings. 支持编辑数据库详情~~
## Precautions
### For customised database users
**⚠️⚠️⚠️: The exist customised database should be recreated if you want to update to version 2.3.0. The new version has a new database structure, and the old database structure is not compatible with the new version to build the index properly.**
### 自定义数据库用户
**⚠️⚠️⚠️: 如果你想要更新到2.3.0版本,你需要重新创建自定义数据库。新版本有一个新的数据库结构,旧的数据库结构无法构建索引。**
## How to use ## How to use
You need seven steps to use this plugin in your Obsidian. You need seven steps to use this plugin in your Obsidian.
@@ -78,50 +85,10 @@ tags:
- web # add more tags if you want - web # add more tags if you want
--- ---
``` ```
<details> <summary> Update </summary>
### 2.2.5 ![](https://minioapi.pjx.ac.cn/img1/2024/07/7a1550aefd71175c981077ce46d03c87.png)
- Update NotionNext function that
- `tags`, `titleicon`, `slug` and `summary` are now optional. You can remove them from the frontmatter if you don't need them.
### 2.2.3
- Fix a bug that 'text' property cannot be synchronized. 修复了一个无法同步'text'属性的bug。
### 2.2.2
- Fix the setting description of database. 修复数据库设置的描述错误。
### 2.2.1
- improve the localisation for the custom properties setting. 改进自定义属性设置的本地化。
**Warning: the edit function for the custom properties is not perfect for now. You need to re-enter all the properties if you want to edit the properties.**
**注意:自定义属性的编辑功能现在还不完善。如果你想编辑属性,你需要重新输入所有的属性。**
### 2.2.0 (Big Update)
- add the support for custom properties in the Notion General database. 支持自定义属性
- [x] `title`, which is the first column of the database
- [x] 'Text'
- [x] 'Number'
- [x] 'Date'
- [x] 'Checkbox'
- [x] 'Select'
- [x] 'Multi-select'
- [x] 'URL'
- [x] 'Email'
- [x] 'Phone'
- [x] 'File' (**Only support external embedded files**)
</details>
![](https://minioapi.pjx.ac.cn/img1/2024/01/0cd99007409feede77bf5a3291e88af3.png)
- Once you create the properties, you can preview the database details in the plugin settings. - Once you create the properties, you can preview the database details in the plugin settings.
![](https://minioapi.pjx.ac.cn/img1/2024/01/665139962cc4cee2a0cb576b508b29f2.png) ![](https://minioapi.pjx.ac.cn/img1/2024/07/9599d77116afad065d2e31129942acc7.png)
--- ---
@@ -133,146 +100,6 @@ Thus, based on the [original author's work](https://github.com/EasyChris/obsidia
--- ---
<details> <summary> Archive Update </summary>
### 2.1.0
- add confirmation interface for deleting a database 增加删除数据库的确认界面
- fix the typo in the edit database modal 修复编辑数据库界面的标题错误
- improve the logic for the database editing 改进数据库编辑界面的逻辑
### 2.0.1
- Add the preview and edit function for database details in the plugin settings. 增加插件设置中数据库详情的预览和编辑功能。
![](https://minioapi.pjx.ac.cn/img1/2024/01/952f1e579daeac35b257ff7d744b0a3d.png)
- Preview:
![](https://minioapi.pjx.ac.cn/img1/2024/01/952f1e579daeac35b257ff7d744b0a3d.png)
- Edit:
![](https://minioapi.pjx.ac.cn/img1/2024/01/ded3d62660f5488c76488304a3fb269e.png)
### 2.0.0 (Big Update)
- redesign the plugin settings UI. From this version, the settings UI will be separated into two parts:
- one for general settings: bannerUrl and your notion username (ID)
- one for database list: You can add new database or delete the database.
- 重新设计了插件设置界面。从这个版本开始,设置界面将被分成两部分:
- 一部分是通用设置bannerUrl和你的notion用户名ID
- 一部分是数据库列表:你可以添加新的数据库或者删除数据库。
![](https://minioapi.pjx.ac.cn/img1/2023/12/f7e89241f45cfee6b902ec4b69dd6f63.png)
- You can add more databases in the plugin settings.
- 你可以在插件设置中添加更多的数据库。
![](https://minioapi.pjx.ac.cn/img1/2023/12/023bf46ebbc92c3991d2c443c575bc80.gif)
- You can sync one note to multiple databases.
- 你可以将一个笔记同步到多个数据库中。
![](https://minioapi.pjx.ac.cn/img1/2023/12/75f793bad756162e46bf41e54166eb32.png)
**Note: You need to add your previous database in the new template.**
**注意:你需要将之前的数据库添加到新的模板中。**
### 1.1.2
- Fix the typo that you cannot sync the markdown file `status` in the frontmatter to NotionNext. You can use `stats` or `status` to sync the status of the post to NotionNext. This update will not affect the function of syncing to General database.
- 修复了一个拼写错误,导致无法同步`status`到NotionNext。现在你可以使用`stats`或者`status`来同步文章的状态到NotionNext。这个更新不会影响到同步到General数据库的功能。
- **Both `stats` and `status` will work, but you can only use one of them.**
- **`stats``status`都可以使用,但是你只能使用其中一个。**
For example,
```yaml
stats: Draft # Draft, Invisible, Published, default is Draft 默认是Draft
# or
status: Draft # Draft, Invisible, Published, default is Draft 默认是Draft
# both of them will work, but you can only use one of them.
```
### 1.1.1
- Fix the setting display bug in Japanese.
- Add Japanese translation.
### 1.1.0
- Fix the custom name setting tab display bug.
- Add a toggle to control whether to sync `tags` since the empty tags may cause the syncing error.
If you switch off the `tags` function in the plugin settings, it will ignore the `tags` in your frontmatter.
If you prefer to sync tags to Notion database, you can switch on the `tags` function in the plugin settings. **You can only use the following format for tags:**
```yaml
tags: #empty tags, option 1
tags: [test,test1,test2] # use the square brackets, option 2
tags:
- test
- test1
- test2 # use the dash option 3
```
### 1.0.1
- Fix the custom name element display bug in the settings.
### 1.0.0 (Big Update)
- From this version, you can **modify the first column name (title column, default: 'title')** as you want. (**Note: You need to have the 'tags' column in your Notion General database, and add `tags:` in your markdown frontmatter. If not, you will receive `network error 400`. But you can leave the `tags:` blank.**)
![](https://minioapi.pjx.ac.cn/img1/2023/11/4a298b9be3990e9d2201bf2f50ca5a0a.png)
Like this:
![](https://minioapi.pjx.ac.cn/img1/2023/11/4cd8d79cd9dd9dde299e39c666cb3473.gif)
- Add a switch button to control whether display the setting tabs in the plugin settings for both NotionNext and Notion General databases.
![](https://minioapi.pjx.ac.cn/img1/2023/11/becb60fc44783842da4b3cf4c322f363.gif)
### 0.2.6
- Add a switch button to control whether to show the upload command in the command palette.
<!-- ![](https://minioapi.pjx.ac.cn/img1/2023/11/147c6a4eaa34da41a6f102558ed77106.png)
If you turn off the button for the General database, you won't see the option for the General database in the upload command list.
If you turn off the button for the NotionNext database, you won't see the option for the NotionNext database in the upload command list.
![](https://minioapi.pjx.ac.cn/img1/2023/11/70b8e4fc2148688ccbd6cfc53ce339a2.png) -->
### 0.2.3
- Fix the bug, now you can update normally.
### 0.2.2
- Support both NotionNext and General Notion database.
- You can have one NotionNext and one General Notion database.
- General Notion database can only have `title` and `tags` columns, and `tags` columns should be the multi-selected property. **the name of the columns is case sensitive. You should use small letter.**
![](https://minioapi.pjx.ac.cn/img1/2023/11/712a12081d855aa60f82a7b46913ab7e.gif)
![](https://minioapi.pjx.ac.cn/img1/2023/11/9de76cecceef74c78884ddfc1c221659.gif)
### 0.2.1
- Restructure the code
### 0.2.0
- From this version, the interactive logic has been rewritten. When you click the ribbon icon, it will display the sync command for all presetting NotionNext databases. You can choose the database you want to sync to. **However, only NotionNext database is supported for now.**
### 0.1.10
- Fix the Chinese support in the settings.
### 0.1.8
- Rebuild the uploadCommand function, and add one button to select the different databases. **However, only NotionNext database is supported for now.**
### 0.1.7
- [x] Removed the `convert tag` option. Now, you can directly add tags in the YAML front matter. If you don't want to add tags, you can delete the tags in the YAML front matter or leave the tags blank.
</details>
<details> <summary> Previous How to Use </summary> <details> <summary> Previous How to Use </summary>
### Precautions ### Precautions

View File

@@ -11,7 +11,7 @@ export interface DatabaseList {
} }
export class FuzzySuggester extends FuzzySuggestModal<DatabaseList>{ export class FuzzySuggester extends FuzzySuggestModal<DatabaseList> {
private plugin: MyPlugin; private plugin: MyPlugin;
private data: DatabaseList[]; private data: DatabaseList[];
private callback: any; private callback: any;

View File

@@ -1,9 +1,9 @@
import { i18nConfig } from "src/lang/I18n"; import { i18nConfig } from "src/lang/I18n";
import {Editor, MarkdownView, setTooltip} from "obsidian"; import { Editor, MarkdownView, setTooltip } from "obsidian";
import { FuzzySuggester, DatabaseList } from "./FuzzySuggester"; import { FuzzySuggester, DatabaseList } from "./FuzzySuggester";
import {uploadCommandCustom, uploadCommandGeneral, uploadCommandNext} from "../upload/uploadCommand"; import { uploadCommandCustom, uploadCommandGeneral, uploadCommandNext } from "../upload/uploadCommand";
import ObsidianSyncNotionPlugin from "src/main"; import ObsidianSyncNotionPlugin from "src/main";
import {DatabaseDetails} from "../ui/settingTabs"; import { DatabaseDetails } from "../ui/settingTabs";
interface Command { interface Command {

View File

@@ -55,32 +55,32 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
await this.saveData(this.settings); await this.saveData(this.settings);
} }
async addDatabaseDetails(dbDetails: DatabaseDetails) { async addDatabaseDetails(dbDetails: DatabaseDetails) {
this.settings.databaseDetails = { this.settings.databaseDetails = {
...this.settings.databaseDetails, ...this.settings.databaseDetails,
[dbDetails.abName]: dbDetails, [dbDetails.abName]: dbDetails,
}; };
await this.saveSettings(); await this.saveSettings();
} }
async deleteDatabaseDetails(dbDetails: DatabaseDetails) { async deleteDatabaseDetails(dbDetails: DatabaseDetails) {
delete this.settings.databaseDetails[dbDetails.abName]; delete this.settings.databaseDetails[dbDetails.abName];
await this.saveSettings(); await this.saveSettings();
} }
async updateDatabaseDetails(dbDetails: DatabaseDetails) { async updateDatabaseDetails(dbDetails: DatabaseDetails) {
// delete the old database details // delete the old database details
delete this.settings.databaseDetails[dbDetails.abName]; delete this.settings.databaseDetails[dbDetails.abName];
this.settings.databaseDetails = { this.settings.databaseDetails = {
...this.settings.databaseDetails, ...this.settings.databaseDetails,
[dbDetails.abName]: dbDetails, [dbDetails.abName]: dbDetails,
}; };
await this.saveSettings(); await this.saveSettings();
} }
} }

View File

@@ -1,5 +1,5 @@
import {App, ButtonComponent, Modal, Setting} from "obsidian"; import { App, ButtonComponent, Modal, Setting } from "obsidian";
import {DatabaseDetails, ObsidianSettingTab} from "./settingTabs"; import { DatabaseDetails, ObsidianSettingTab } from "./settingTabs";
import ObsidianSyncNotionPlugin from "../main"; import ObsidianSyncNotionPlugin from "../main";
export class DeleteModal extends Modal { export class DeleteModal extends Modal {
@@ -21,12 +21,12 @@ export class DeleteModal extends Modal {
this.containerEl.addClass("delete-modal"); this.containerEl.addClass("delete-modal");
this.titleEl.setText('Delete Database'); this.titleEl.setText('Delete Database');
let {contentEl} = this; let { contentEl } = this;
contentEl.empty(); contentEl.empty();
const deleteDiv = contentEl.createDiv('delete-div'); const deleteDiv = contentEl.createDiv('delete-div');
deleteDiv.createEl('h4', {text: 'Are you sure you want to delete the following database?'}); deleteDiv.createEl('h4', { text: 'Are you sure you want to delete the following database?' });
deleteDiv.createEl('h2', {text: this.dbDetails.fullName + ' (' + this.dbDetails.abName + ', ' + this.dbDetails.format +')'}); deleteDiv.createEl('h2', { text: this.dbDetails.fullName + ' (' + this.dbDetails.abName + ', ' + this.dbDetails.format + ')' });
// add delete button // add delete button

View File

@@ -1,4 +1,4 @@
import { App, ButtonComponent, Modal, Setting } from "obsidian"; import { App, ButtonComponent, Setting } from "obsidian";
import { customProperty, SettingModal } from "./settingModal"; import { customProperty, SettingModal } from "./settingModal";
import ObsidianSyncNotionPlugin from "../main"; import ObsidianSyncNotionPlugin from "../main";
import { DatabaseDetails, ObsidianSettingTab } from "./settingTabs"; import { DatabaseDetails, ObsidianSettingTab } from "./settingTabs";
@@ -133,8 +133,8 @@ export class EditModal extends SettingModal {
.onClick(async () => { .onClick(async () => {
this.dataTemp.savedTempInd = true; this.dataTemp.savedTempInd = true;
this.dataTemp.savedTemp = true; this.dataTemp.savedTemp = true;
console.log(this.dataTemp); // console.log(this.dataTemp);
console.log(this.dataPrev); // console.log(this.dataPrev);
this.close(); this.close();
}); });
} }
@@ -144,8 +144,8 @@ export class EditModal extends SettingModal {
.setTooltip('Cancel') .setTooltip('Cancel')
.setIcon('cross') .setIcon('cross')
.onClick(() => { .onClick(() => {
console.log(this.dataTemp); // console.log(this.dataTemp);
console.log(this.dataPrev); // console.log(this.dataPrev);
this.close(); this.close();
}); });
} }

View File

@@ -1,15 +1,15 @@
import {App, ExtraButtonComponent, Modal, Notice, Setting} from "obsidian"; import { App, ExtraButtonComponent, Modal, Notice, Setting } from "obsidian";
import ObsidianSyncNotionPlugin from "../main"; import ObsidianSyncNotionPlugin from "../main";
import {DatabaseDetails, ObsidianSettingTab} from "./settingTabs"; import { DatabaseDetails, ObsidianSettingTab } from "./settingTabs";
import {customProperty} from "./settingModal"; import { customProperty } from "./settingModal";
import {i18nConfig} from "../lang/I18n"; import { i18nConfig } from "../lang/I18n";
export class PreviewModal extends Modal { export class PreviewModal extends Modal {
plugin: ObsidianSyncNotionPlugin; plugin: ObsidianSyncNotionPlugin;
settingTab: ObsidianSettingTab; settingTab: ObsidianSettingTab;
dbDetails: DatabaseDetails; dbDetails: DatabaseDetails;
constructor(app:App, plugin: ObsidianSyncNotionPlugin, settingTab: ObsidianSettingTab, dbDetails: DatabaseDetails) { constructor(app: App, plugin: ObsidianSyncNotionPlugin, settingTab: ObsidianSettingTab, dbDetails: DatabaseDetails) {
super(app); super(app);
this.plugin = plugin; this.plugin = plugin;
this.settingTab = settingTab; this.settingTab = settingTab;
@@ -26,25 +26,25 @@ export class PreviewModal extends Modal {
const previewEl = contentEl.createDiv('preview-content') const previewEl = contentEl.createDiv('preview-content')
const dbFormatEl = new Setting(previewEl) const dbFormatEl = new Setting(previewEl)
dbFormatEl dbFormatEl
.setName('Database Format') .setName('Database Format')
.addText(text => text .addText(text => text
.setValue(this.dbDetails.format) .setValue(this.dbDetails.format)
.setDisabled(true)); .setDisabled(true));
const dbFullEl = new Setting(previewEl) const dbFullEl = new Setting(previewEl)
dbFullEl dbFullEl
.setName('Database Full Name') .setName('Database Full Name')
.addText(text => text .addText(text => text
.setValue(this.dbDetails.fullName) .setValue(this.dbDetails.fullName)
.setDisabled(true)); .setDisabled(true));
const dbAbbrEl = new Setting(previewEl) const dbAbbrEl = new Setting(previewEl)
dbAbbrEl dbAbbrEl
.setName('Database Abbreviate Name') .setName('Database Abbreviate Name')
.addText(text => text .addText(text => text
.setValue(this.dbDetails.abName) .setValue(this.dbDetails.abName)
.setDisabled(true)); .setDisabled(true));
// .controlEl.createEl('p', { text: this.dbDetails.abName }) // .controlEl.createEl('p', { text: this.dbDetails.abName })
// Setting for toggle and copy buttons // Setting for toggle and copy buttons
@@ -124,7 +124,6 @@ export class PreviewModal extends Modal {
const customPrv = previewEl.createDiv("custom-tabs"); const customPrv = previewEl.createDiv("custom-tabs");
this.previewPropertyLine(previewEl, this.dbDetails.customProperties); this.previewPropertyLine(previewEl, this.dbDetails.customProperties);
} }

View File

@@ -1,31 +1,29 @@
import {App, ButtonComponent, Modal, PluginSettingTab, Setting} from "obsidian"; import { App, ButtonComponent, PluginSettingTab, Setting } from "obsidian";
import {i18nConfig} from "../lang/I18n"; import { i18nConfig } from "../lang/I18n";
import ObsidianSyncNotionPlugin from "../main"; import ObsidianSyncNotionPlugin from "../main";
import {SettingModal} from "./settingModal"; import { SettingModal } from "./settingModal";
import {set} from "yaml/dist/schema/yaml-1.1/set"; import { PreviewModal } from "./PreviewModal";
import {PreviewModal} from "./PreviewModal"; import { EditModal } from "./EditModal";
import {EditModal} from "./EditModal"; import { DeleteModal } from "./DeleteModal";
import {DeleteModal} from "./DeleteModal";
export interface PluginSettings { export interface PluginSettings {
NextButton: boolean; NextButton: boolean;
notionAPINext: string; notionAPINext: string;
databaseIDNext: string; databaseIDNext: string;
bannerUrl: string; bannerUrl: string;
notionUser: string; notionUser: string;
NotionLinkDisplay: boolean; proxy: string;
proxy: string; GeneralButton: boolean;
GeneralButton: boolean; tagButton: boolean;
tagButton: boolean; customTitleButton: boolean;
customTitleButton: boolean; customTitleName: string;
customTitleName: string; notionAPIGeneral: string;
notionAPIGeneral: string; databaseIDGeneral: string;
databaseIDGeneral: string; CustomButton: boolean;
CustomButton: boolean; CustomValues: string;
CustomValues: string; notionAPICustom: string;
notionAPICustom: string; databaseIDCustom: string;
databaseIDCustom: string; [key: string]: any;
[key: string]: any;
databaseDetails: Record<string, DatabaseDetails> databaseDetails: Record<string, DatabaseDetails>
} }
@@ -38,58 +36,54 @@ export interface DatabaseDetails {
tagButton: boolean; tagButton: boolean;
customTitleButton: boolean; customTitleButton: boolean;
customTitleName: string; customTitleName: string;
customProperties:{ customName: string, customType: string, index: number}[]; customProperties: { customName: string, customType: string, index: number }[];
// customValues: string; // customValues: string;
saved: boolean; saved: boolean;
} }
export const DEFAULT_SETTINGS: PluginSettings = { export const DEFAULT_SETTINGS: PluginSettings = {
NextButton: true, NextButton: true,
notionAPINext: "", notionAPINext: "",
databaseIDNext: "", databaseIDNext: "",
bannerUrl: "", bannerUrl: "",
notionUser: "", notionUser: "",
NotionLinkDisplay: true, proxy: "",
proxy: "", GeneralButton: true,
GeneralButton: true, tagButton: true,
tagButton: true, customTitleButton: false,
customTitleButton: false, customTitleName: "",
customTitleName: "", notionAPIGeneral: "",
notionAPIGeneral: "", databaseIDGeneral: "",
databaseIDGeneral: "", CustomButton: false,
CustomButton: false, CustomValues: "",
CustomValues: "", notionAPICustom: "",
notionAPICustom: "", databaseIDCustom: "",
databaseIDCustom: "",
databaseDetails: {}, databaseDetails: {},
}; };
export class ObsidianSettingTab extends PluginSettingTab { export class ObsidianSettingTab extends PluginSettingTab {
plugin: ObsidianSyncNotionPlugin; plugin: ObsidianSyncNotionPlugin;
databaseEl: HTMLDivElement; databaseEl: HTMLDivElement;
constructor(app: App, plugin: ObsidianSyncNotionPlugin) { constructor(app: App, plugin: ObsidianSyncNotionPlugin) {
super(app, plugin); super(app, plugin);
this.plugin = plugin; this.plugin = plugin;
} }
display(): void { display(): void {
const { containerEl } = this; const { containerEl } = this;
containerEl.empty(); containerEl.empty();
// General Settings // General Settings
containerEl.createEl('h2', { text: i18nConfig.GeneralSetting }); containerEl.createEl('h2', { text: i18nConfig.GeneralSetting });
this.createSettingEl(containerEl, i18nConfig.BannerUrl, i18nConfig.BannerUrlDesc, 'text', i18nConfig.BannerUrlText, this.plugin.settings.bannerUrl, 'bannerUrl') this.createSettingEl(containerEl, i18nConfig.BannerUrl, i18nConfig.BannerUrlDesc, 'text', i18nConfig.BannerUrlText, this.plugin.settings.bannerUrl, 'bannerUrl')
this.createSettingEl(containerEl, i18nConfig.NotionUser, i18nConfig.NotionUserDesc, 'text', i18nConfig.NotionUserText, this.plugin.settings.notionUser, 'notionUser') this.createSettingEl(containerEl, i18nConfig.NotionUser, i18nConfig.NotionUserDesc, 'text', i18nConfig.NotionUserText, this.plugin.settings.notionUser, 'notionUser')
this.createSettingEl(containerEl, i18nConfig.NotionLinkDisplay, i18nConfig.NotionLinkDisplayDesc, 'toggle', i18nConfig.NotionLinkDisplay, this.plugin.settings.NotionLinkDisplay, 'NotionLinkDisplay')
// add new button // add new button
new Setting(containerEl) new Setting(containerEl)
.setName("Add New Database") .setName("Add New Database")
.setDesc("Add New Database") .setDesc("Add New Database")
@@ -129,73 +123,74 @@ export class ObsidianSettingTab extends PluginSettingTab {
}); });
// new section to display all created database // new section to display all created database
containerEl.createEl('h2', {text: "Database List"}); containerEl.createEl('h2', { text: "Database List" });
this.databaseEl = containerEl.createDiv('database-list'); this.databaseEl = containerEl.createDiv('database-list');
// list all created database // list all created database
this.showDatabase(); this.showDatabase();
} }
// create a function to create a div with a style for pop over elements // create a function to create a div with a style for pop over elements
public createStyleDiv(className: string, commandValue: boolean = false) { // public createStyleDiv(className: string, commandValue: boolean = false) {
return this.containerEl.createDiv(className, (div) => { // return this.containerEl.createDiv(className, (div) => {
this.updateSettingEl(div, commandValue); // this.updateSettingEl(div, commandValue);
}); // });
} // }
// update the setting display style in the setting tab
public updateSettingEl(element: HTMLElement, commandValue: boolean) {
element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none";
element.style.paddingTop = commandValue ? "0.75em" : "0";
element.style.display = commandValue ? "block" : "none";
element.style.alignItems = "center";
}
// function to add one setting element in the setting tab. // update the setting display style in the setting tab
public createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any, settingsKey: string) { public updateSettingEl(element: HTMLElement, commandValue: boolean) {
if (type === 'password') { element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none";
return new Setting(containerEl) element.style.paddingTop = commandValue ? "0.75em" : "0";
.setName(name) element.style.display = commandValue ? "block" : "none";
.setDesc(desc) element.style.alignItems = "center";
.addText((text) => { }
text.inputEl.type = type;
return text // function to add one setting element in the setting tab.
.setPlaceholder(placeholder) public createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any, settingsKey: string) {
.setValue(holderValue) if (type === 'password') {
.onChange(async (value) => { return new Setting(containerEl)
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly .setName(name)
await this.plugin.saveSettings(); .setDesc(desc)
}) .addText((text) => {
}); text.inputEl.type = type;
} else if (type === 'toggle') { return text
return new Setting(containerEl) .setPlaceholder(placeholder)
.setName(name) .setValue(holderValue)
.setDesc(desc) .onChange(async (value) => {
.addToggle((toggle) => this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
toggle await this.plugin.saveSettings();
.setValue(holderValue) })
.onChange(async (value) => { });
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly } else if (type === 'toggle') {
await this.plugin.saveSettings(); return new Setting(containerEl)
await this.plugin.commands.updateCommand(); .setName(name)
}) .setDesc(desc)
); .addToggle((toggle) =>
} else if (type === 'text') { toggle
return new Setting(containerEl) .setValue(holderValue)
.setName(name) .onChange(async (value) => {
.setDesc(desc) this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
.addText((text) => await this.plugin.saveSettings();
text await this.plugin.commands.updateCommand();
.setPlaceholder(placeholder) })
.setValue(holderValue) );
.onChange(async (value) => { } else if (type === 'text') {
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly return new Setting(containerEl)
await this.plugin.saveSettings(); .setName(name)
await this.plugin.commands.updateCommand(); .setDesc(desc)
}) .addText((text) =>
); text
} .setPlaceholder(placeholder)
} .setValue(holderValue)
.onChange(async (value) => {
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
await this.plugin.saveSettings();
await this.plugin.commands.updateCommand();
})
);
}
}
// function to show all the database details // function to show all the database details
showDatabase() { showDatabase() {
@@ -211,8 +206,8 @@ export class ObsidianSettingTab extends PluginSettingTab {
.setDesc(dbDetails.format) .setDesc(dbDetails.format)
// add a button for preview data // add a button for preview data
settingEl settingEl
.addButton((button: ButtonComponent): ButtonComponent => { .addButton((button: ButtonComponent): ButtonComponent => {
return button return button
.setTooltip("Preview Database") .setTooltip("Preview Database")
@@ -224,8 +219,8 @@ export class ObsidianSettingTab extends PluginSettingTab {
}); });
}); });
// add a button for edit data // add a button for edit data
settingEl settingEl
.addButton((button: ButtonComponent): ButtonComponent => { .addButton((button: ButtonComponent): ButtonComponent => {
return button return button
.setTooltip("Edit Database") .setTooltip("Edit Database")
@@ -272,11 +267,11 @@ export class ObsidianSettingTab extends PluginSettingTab {
} }
} }
modal.open (); modal.open();
}); });
}); });
settingEl settingEl
.addButton((button: ButtonComponent): ButtonComponent => { .addButton((button: ButtonComponent): ButtonComponent => {
return button return button
.setTooltip("Delete Database") .setTooltip("Delete Database")

View File

@@ -1,6 +1,6 @@
import { App, Notice, TFile } from "obsidian"; import { App, Notice, TFile } from "obsidian";
import ObsidianSyncNotionPlugin from "../main"; import ObsidianSyncNotionPlugin from "../main";
import {DatabaseDetails} from "../ui/settingTabs"; import { DatabaseDetails } from "../ui/settingTabs";
export async function updateYamlInfo( export async function updateYamlInfo(
yamlContent: string, yamlContent: string,
@@ -8,14 +8,14 @@ export async function updateYamlInfo(
res: any, res: any,
app: App, app: App,
plugin: ObsidianSyncNotionPlugin, plugin: ObsidianSyncNotionPlugin,
dbDetails: DatabaseDetails, dbDetails: DatabaseDetails,
) { ) {
let { url, id } = res.json let { url, id } = res.json
// replace www to notionID // replace www to notionID
const { notionUser } = plugin.settings; const { notionUser } = plugin.settings;
const { abName } = dbDetails const { abName } = dbDetails
const notionIDKey = `NotionID-${abName}`; const notionIDKey = `NotionID-${abName}`;
const linkKey = `link-${abName}`; const linkKey = `link-${abName}`;
if (notionUser !== "") { if (notionUser !== "") {
// replace url str "www" to notionID // replace url str "www" to notionID

View File

@@ -1,13 +1,13 @@
import {i18nConfig} from "../lang/I18n"; import { i18nConfig } from "../lang/I18n";
import {App, Notice} from "obsidian"; import { App, Notice } from "obsidian";
import {Upload2NotionNext} from "./upload_next/Upload2NotionNext"; import { Upload2NotionNext } from "./upload_next/Upload2NotionNext";
import {Upload2NotionGeneral} from "./upload_general/Upload2NotionGeneral"; import { Upload2NotionGeneral } from "./upload_general/Upload2NotionGeneral";
import {Upload2NotionCustom} from "./upoload_custom/Upload2NotionCustom"; import { Upload2NotionCustom } from "./upoload_custom/Upload2NotionCustom";
import {DatabaseDetails, PluginSettings} from "../ui/settingTabs"; import { DatabaseDetails, PluginSettings } from "../ui/settingTabs";
import ObsidianSyncNotionPlugin from "../main"; import ObsidianSyncNotionPlugin from "../main";
import {getNowFileMarkdownContentNext} from "./upload_next/getMarkdownNext"; import { getNowFileMarkdownContentNext } from "./upload_next/getMarkdownNext";
import {getNowFileMarkdownContentGeneral} from "./upload_general/getMarkdownGeneral"; import { getNowFileMarkdownContentGeneral } from "./upload_general/getMarkdownGeneral";
import {getNowFileMarkdownContentCustom} from "./upoload_custom/getMarkdownCustom"; import { getNowFileMarkdownContentCustom } from "./upoload_custom/getMarkdownCustom";
export async function uploadCommandNext( export async function uploadCommandNext(
plugin: ObsidianSyncNotionPlugin, plugin: ObsidianSyncNotionPlugin,
@@ -16,7 +16,7 @@ export async function uploadCommandNext(
app: App, app: App,
) { ) {
const {notionAPI, databaseID} = dbDetails; const { notionAPI, databaseID } = dbDetails;
// Check if NNon exists // Check if NNon exists
// if (NNon === undefined) { // if (NNon === undefined) {
@@ -49,7 +49,7 @@ export async function uploadCommandNext(
} = await getNowFileMarkdownContentNext(app, settings) } = await getNowFileMarkdownContentNext(app, settings)
if (markDownData) { if (markDownData) {
const {basename} = nowFile; const { basename } = nowFile;
const upload = new Upload2NotionNext(plugin, dbDetails); const upload = new Upload2NotionNext(plugin, dbDetails);
const res = await upload.syncMarkdownToNotionNext(basename, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app); const res = await upload.syncMarkdownToNotionNext(basename, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app);
@@ -70,7 +70,7 @@ export async function uploadCommandGeneral(
app: App, app: App,
) { ) {
const {notionAPI, databaseID} = dbDetails; const { notionAPI, databaseID } = dbDetails;
// Check if the user has set up the Notion API and database ID // Check if the user has set up the Notion API and database ID
if (notionAPI === "" || databaseID === "") { if (notionAPI === "" || databaseID === "") {
@@ -79,10 +79,10 @@ export async function uploadCommandGeneral(
return; return;
} }
const {markDownData, nowFile, cover, tags} = await getNowFileMarkdownContentGeneral(app, settings) const { markDownData, nowFile, cover, tags } = await getNowFileMarkdownContentGeneral(app, settings)
if (markDownData) { if (markDownData) {
const {basename} = nowFile; const { basename } = nowFile;
const upload = new Upload2NotionGeneral(plugin, dbDetails); const upload = new Upload2NotionGeneral(plugin, dbDetails);
const res = await upload.syncMarkdownToNotionGeneral(basename, cover, tags, markDownData, nowFile, this.app); const res = await upload.syncMarkdownToNotionGeneral(basename, cover, tags, markDownData, nowFile, this.app);
@@ -104,7 +104,7 @@ export async function uploadCommandCustom(
app: App, app: App,
) { ) {
const {notionAPI, databaseID} = settings; const { notionAPI, databaseID } = settings;
// Check if the user has set up the Notion API and database ID // Check if the user has set up the Notion API and database ID
if (notionAPI === "" || databaseID === "") { if (notionAPI === "" || databaseID === "") {
@@ -113,10 +113,10 @@ export async function uploadCommandCustom(
return; return;
} }
const {markDownData, nowFile, cover, customValues} = await getNowFileMarkdownContentCustom(app, dbDetails) const { markDownData, nowFile, cover, customValues } = await getNowFileMarkdownContentCustom(app, dbDetails)
if (markDownData) { if (markDownData) {
const { basename} = nowFile; const { basename } = nowFile;
const upload = new Upload2NotionCustom(plugin, dbDetails); const upload = new Upload2NotionCustom(plugin, dbDetails);
const res = await upload.syncMarkdownToNotionCustom(cover, customValues, markDownData, nowFile, this.app); const res = await upload.syncMarkdownToNotionCustom(cover, customValues, markDownData, nowFile, this.app);

View File

@@ -1,10 +1,10 @@
import {App, Notice, requestUrl, TFile} from "obsidian"; import { App, Notice, requestUrl, TFile } from "obsidian";
import {Client} from '@notionhq/client'; import { Client } from '@notionhq/client';
import {markdownToBlocks,} from "@tryfabric/martian"; import { markdownToBlocks, } from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
// import * as yaml from "yaml" // import * as yaml from "yaml"
import MyPlugin from "src/main"; import MyPlugin from "src/main";
import {DatabaseDetails} from "../../ui/settingTabs"; import { DatabaseDetails } from "../../ui/settingTabs";
export class UploadBaseGeneral { export class UploadBaseGeneral {
plugin: MyPlugin; plugin: MyPlugin;
@@ -19,7 +19,7 @@ export class UploadBaseGeneral {
async deletePage(notionID: string) { async deletePage(notionID: string) {
const {notionAPI} = this.dbDetails const { notionAPI } = this.dbDetails
return requestUrl({ return requestUrl({
url: `https://api.notion.com/v1/blocks/${notionID}`, url: `https://api.notion.com/v1/blocks/${notionID}`,
method: 'DELETE', method: 'DELETE',
@@ -33,15 +33,15 @@ export class UploadBaseGeneral {
} }
async getDataBase(databaseID: string) { async getDataBase(databaseID: string) {
const {notionAPI} = this.dbDetails const { notionAPI } = this.dbDetails
const response = await requestUrl({ const response = await requestUrl({
url: `https://api.notion.com/v1/databases/${databaseID}`, url: `https://api.notion.com/v1/databases/${databaseID}`,
method: 'GET', method: 'GET',
headers: { headers: {
'Authorization': 'Bearer ' + notionAPI, 'Authorization': 'Bearer ' + notionAPI,
'Notion-Version': '2022-06-28', 'Notion-Version': '2022-06-28',
}
} }
}
) )
// Check if cover is present in the JSON response and then get the URL // Check if cover is present in the JSON response and then get the URL

View File

@@ -4,7 +4,7 @@ import { markdownToBlocks } from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
// import * as yaml from "yaml" // import * as yaml from "yaml"
import MyPlugin from "src/main"; import MyPlugin from "src/main";
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs"; import { DatabaseDetails, PluginSettings } from "../../ui/settingTabs";
import { UploadBaseGeneral } from "./BaseUpload2NotionGeneral"; import { UploadBaseGeneral } from "./BaseUpload2NotionGeneral";
import { updateYamlInfo } from "../updateYaml"; import { updateYamlInfo } from "../updateYaml";
@@ -138,7 +138,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
const file2Block = markdownToBlocks(__content, options); const file2Block = markdownToBlocks(__content, options);
const frontmasster = const frontmasster =
app.metadataCache.getFileCache(nowFile)?.frontmatter; app.metadataCache.getFileCache(nowFile)?.frontmatter;
const {abName} = this.dbDetails const { abName } = this.dbDetails
const notionIDKey = `NotionID-${abName}`; const notionIDKey = `NotionID-${abName}`;
const notionID = frontmasster ? frontmasster[notionIDKey] : null; const notionID = frontmasster ? frontmasster[notionIDKey] : null;

View File

@@ -1,6 +1,6 @@
import {App, Notice} from "obsidian"; import { App, Notice } from "obsidian";
import {i18nConfig} from "../../lang/I18n"; import { i18nConfig } from "../../lang/I18n";
import {PluginSettings} from "../../ui/settingTabs"; import { PluginSettings } from "../../ui/settingTabs";
export async function getNowFileMarkdownContentGeneral( export async function getNowFileMarkdownContentGeneral(
app: App, app: App,

View File

@@ -4,21 +4,21 @@ import { markdownToBlocks, } from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
// import * as yaml from "yaml" // import * as yaml from "yaml"
import MyPlugin from "src/main"; import MyPlugin from "src/main";
import {DatabaseDetails} from "../../ui/settingTabs"; import { DatabaseDetails } from "../../ui/settingTabs";
export class UploadBaseNext { export class UploadBaseNext {
plugin: MyPlugin; plugin: MyPlugin;
notion: Client; notion: Client;
agent: any; agent: any;
dbDetails: DatabaseDetails dbDetails: DatabaseDetails
constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) { constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
this.plugin = plugin; this.plugin = plugin;
this.dbDetails = dbDetails this.dbDetails = dbDetails
} }
async deletePage(notionID: string) { async deletePage(notionID: string) {
const {notionAPI} = this.dbDetails const { notionAPI } = this.dbDetails
return requestUrl({ return requestUrl({
url: `https://api.notion.com/v1/blocks/${notionID}`, url: `https://api.notion.com/v1/blocks/${notionID}`,
method: 'DELETE', method: 'DELETE',
@@ -32,7 +32,7 @@ export class UploadBaseNext {
} }
async getDataBase(databaseID: string) { async getDataBase(databaseID: string) {
const {notionAPI} = this.dbDetails const { notionAPI } = this.dbDetails
const response = await requestUrl({ const response = await requestUrl({
url: `https://api.notion.com/v1/databases/${databaseID}`, url: `https://api.notion.com/v1/databases/${databaseID}`,

View File

@@ -5,17 +5,17 @@ import { markdownToBlocks, } from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
// import * as yaml from "yaml" // import * as yaml from "yaml"
import MyPlugin from "src/main"; import MyPlugin from "src/main";
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs"; import { DatabaseDetails, PluginSettings } from "../../ui/settingTabs";
import { updateYamlInfo } from "../updateYaml"; import { updateYamlInfo } from "../updateYaml";
import {LIMITS, paragraph} from "@tryfabric/martian/src/notion"; import { LIMITS, paragraph } from "@tryfabric/martian/src/notion";
export class Upload2NotionNext extends UploadBaseNext { export class Upload2NotionNext extends UploadBaseNext {
settings: PluginSettings; settings: PluginSettings;
dbDetails: DatabaseDetails dbDetails: DatabaseDetails
constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) { constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
super(plugin, dbDetails); super(plugin, dbDetails);
this.dbDetails = dbDetails this.dbDetails = dbDetails
} }
// 因为需要解析notion的block进行对比非常的麻烦 // 因为需要解析notion的block进行对比非常的麻烦
@@ -38,7 +38,7 @@ export class Upload2NotionNext extends UploadBaseNext {
) { ) {
await this.deletePage(notionID) await this.deletePage(notionID)
const { databaseID} = this.dbDetails const { databaseID } = this.dbDetails
const databaseCover = await this.getDataBase(databaseID) const databaseCover = await this.getDataBase(databaseID)
@@ -78,10 +78,10 @@ export class Upload2NotionNext extends UploadBaseNext {
childArr: any childArr: any
) { ) {
const { const {
databaseID, databaseID,
notionAPI notionAPI
} = this.dbDetails } = this.dbDetails
const bodyString: any = { const bodyString: any = {
@@ -141,47 +141,47 @@ export class Upload2NotionNext extends UploadBaseNext {
children: childArr, children: childArr,
} }
// add tags // add tags
if (tags) { if (tags) {
bodyString.properties.tags = { bodyString.properties.tags = {
multi_select: tags.map(tag => { multi_select: tags.map(tag => {
return { "name": tag } return { "name": tag }
}) })
} }
} }
// add title icon // add title icon
if (emoji) { if (emoji) {
bodyString.icon = { bodyString.icon = {
emoji: emoji emoji: emoji
} }
} }
// add slug // add slug
if (slug) { if (slug) {
bodyString.properties.slug = { bodyString.properties.slug = {
rich_text: [ rich_text: [
{ {
text: { text: {
content: slug content: slug
} }
} }
] ]
} }
} }
// check if summary is available // check if summary is available
if (summary) { if (summary) {
bodyString.properties.summary = { bodyString.properties.summary = {
rich_text: [ rich_text: [
{ {
text: { text: {
content: summary content: summary
} }
} }
] ]
} }
} }
@@ -238,41 +238,41 @@ export class Upload2NotionNext extends UploadBaseNext {
nowFile: TFile, nowFile: TFile,
app: App, app: App,
): Promise<any> { ): Promise<any> {
const options = { const options = {
notionLimits: { notionLimits: {
truncate: false, truncate: false,
} }
} }
let res: any let res: any
const yamlContent: any = yamlFrontMatter.loadFront(markdown); const yamlContent: any = yamlFrontMatter.loadFront(markdown);
const __content = yamlContent.__content const __content = yamlContent.__content
const file2Block = markdownToBlocks(__content, options); const file2Block = markdownToBlocks(__content, options);
const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter
const {abName} = this.dbDetails const { abName } = this.dbDetails
const notionIDKey = `NotionID-${abName}`; const notionIDKey = `NotionID-${abName}`;
const notionID = frontmasster ? frontmasster[notionIDKey] : null; const notionID = frontmasster ? frontmasster[notionIDKey] : null;
// increase the limits // increase the limits
// Motivated by https://github.com/tryfabric/martian/issues/51 // Motivated by https://github.com/tryfabric/martian/issues/51
file2Block.forEach((block,index) => { file2Block.forEach((block, index) => {
if ( if (
block.type === 'paragraph' && block.type === 'paragraph' &&
block.paragraph.rich_text.length > LIMITS.RICH_TEXT_ARRAYS block.paragraph.rich_text.length > LIMITS.RICH_TEXT_ARRAYS
) { ) {
const newParagraphBlocks: any[] = [] const newParagraphBlocks: any[] = []
const chunk:any = [] const chunk: any = []
const richTextChunks = chunk(block.paragraph.rich_text, 100) const richTextChunks = chunk(block.paragraph.rich_text, 100)
richTextChunks.forEach((chunk: any) => { richTextChunks.forEach((chunk: any) => {
newParagraphBlocks.push(paragraph(chunk)) newParagraphBlocks.push(paragraph(chunk))
}) })
file2Block.splice(index, 1, ...newParagraphBlocks) file2Block.splice(index, 1, ...newParagraphBlocks)
} }
}) })
if (notionID) { if (notionID) {
res = await this.updatePage( res = await this.updatePage(

View File

@@ -13,7 +13,7 @@ export async function getNowFileMarkdownContentNext(
let type = ''; let type = '';
let slug = ''; let slug = '';
let stats = ''; let stats = '';
let status = ''; let status = '';
let category = ''; let category = '';
let summary = ''; let summary = '';
let paword = ''; let paword = '';

View File

@@ -1,24 +1,24 @@
import {App, Notice, requestUrl, TFile} from "obsidian"; import { App, Notice, requestUrl, TFile } from "obsidian";
import {Client} from '@notionhq/client'; import { Client } from '@notionhq/client';
import {markdownToBlocks,} from "@tryfabric/martian"; import { markdownToBlocks, } from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
// import * as yaml from "yaml" // import * as yaml from "yaml"
import MyPlugin from "src/main"; import MyPlugin from "src/main";
import {DatabaseDetails} from "../../ui/settingTabs"; import { DatabaseDetails } from "../../ui/settingTabs";
export class UploadBaseCustom { export class UploadBaseCustom {
plugin: MyPlugin; plugin: MyPlugin;
notion: Client; notion: Client;
agent: any; agent: any;
dbDetails: DatabaseDetails dbDetails: DatabaseDetails
constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) { constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
this.plugin = plugin; this.plugin = plugin;
this.dbDetails = dbDetails this.dbDetails = dbDetails
} }
async deletePage(notionID: string) { async deletePage(notionID: string) {
const {notionAPI} = this.dbDetails const { notionAPI } = this.dbDetails
return requestUrl({ return requestUrl({
url: `https://api.notion.com/v1/blocks/${notionID}`, url: `https://api.notion.com/v1/blocks/${notionID}`,
method: 'DELETE', method: 'DELETE',
@@ -32,15 +32,15 @@ export class UploadBaseCustom {
} }
async getDataBase(databaseID: string) { async getDataBase(databaseID: string) {
const {notionAPI} = this.dbDetails const { notionAPI } = this.dbDetails
const response = await requestUrl({ const response = await requestUrl({
url: `https://api.notion.com/v1/databases/${databaseID}`, url: `https://api.notion.com/v1/databases/${databaseID}`,
method: 'GET', method: 'GET',
headers: { headers: {
'Authorization': 'Bearer ' + notionAPI, 'Authorization': 'Bearer ' + notionAPI,
'Notion-Version': '2022-06-28', 'Notion-Version': '2022-06-28',
}
} }
}
) )
// Check if cover is present in the JSON response and then get the URL // Check if cover is present in the JSON response and then get the URL

View File

@@ -1,11 +1,11 @@
import {App, Notice, requestUrl, TFile} from "obsidian"; import { App, Notice, requestUrl, TFile } from "obsidian";
import {markdownToBlocks} from "@tryfabric/martian"; import { markdownToBlocks } from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter"; import * as yamlFrontMatter from "yaml-front-matter";
// import * as yaml from "yaml" // import * as yaml from "yaml"
import MyPlugin from "src/main"; import MyPlugin from "src/main";
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs"; import { DatabaseDetails, PluginSettings } from "../../ui/settingTabs";
import {updateYamlInfo} from "../updateYaml"; import { updateYamlInfo } from "../updateYaml";
import {UploadBaseCustom} from "./BaseUpload2NotionCustom"; import { UploadBaseCustom } from "./BaseUpload2NotionCustom";
export class Upload2NotionCustom extends UploadBaseCustom { export class Upload2NotionCustom extends UploadBaseCustom {
settings: PluginSettings; settings: PluginSettings;
@@ -26,7 +26,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
) { ) {
await this.deletePage(notionID); await this.deletePage(notionID);
const {databaseID} = this.dbDetails; const { databaseID } = this.dbDetails;
const databaseCover = await this.getDataBase( const databaseCover = await this.getDataBase(
databaseID databaseID
@@ -109,7 +109,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
const file2Block = markdownToBlocks(__content, options); const file2Block = markdownToBlocks(__content, options);
const frontmasster = const frontmasster =
app.metadataCache.getFileCache(nowFile)?.frontmatter; app.metadataCache.getFileCache(nowFile)?.frontmatter;
const {abName} = this.dbDetails const { abName } = this.dbDetails
const notionIDKey = `NotionID-${abName}`; const notionIDKey = `NotionID-${abName}`;
const notionID = frontmasster ? frontmasster[notionIDKey] : null; const notionID = frontmasster ? frontmasster[notionIDKey] : null;
@@ -207,7 +207,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
}; };
case "multi_select": case "multi_select":
return { return {
multi_select: Array.isArray(value) ? value.map(item => ({name: item})) : [{name: value}], multi_select: Array.isArray(value) ? value.map(item => ({ name: item })) : [{ name: value }],
}; };
} }
} }
@@ -221,9 +221,9 @@ export class Upload2NotionCustom extends UploadBaseCustom {
const properties: { [key: string]: any } = {}; const properties: { [key: string]: any } = {};
// Only include custom properties that have values // Only include custom properties that have values
customProperties.forEach(({customName, customType}) => { customProperties.forEach(({ customName, customType }) => {
if (customValues[customName] !== undefined) { if (customValues[customName] !== undefined) {
properties[customName] = this.buildPropertyObject(customName, customType, customValues); properties[customName] = this.buildPropertyObject(customName, customType, customValues);
} }
} }
); );

View File

@@ -1,6 +1,6 @@
import {App, Notice} from "obsidian"; import { App, Notice } from "obsidian";
import {i18nConfig} from "../../lang/I18n"; import { i18nConfig } from "../../lang/I18n";
import {DatabaseDetails} from "../../ui/settingTabs"; import { DatabaseDetails } from "../../ui/settingTabs";
export async function getNowFileMarkdownContentCustom( export async function getNowFileMarkdownContentCustom(
app: App, app: App,