mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 16:35:57 +08:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c3ec6881e | |||
|
|
a80155fafc | ||
| 3a814b8390 | |||
| bb522db9a2 | |||
| 201f72ae0e | |||
| be6f192dd8 | |||
| 4ce1019094 | |||
| 095c608511 | |||
| 2d8d7fb11a | |||
| 36725cb699 | |||
|
|
654e7e854d | ||
|
|
fa67f08512 | ||
|
|
7e42ef49a7 | ||
|
|
5a95aa0acc | ||
|
|
ded01ce678 | ||
|
|
3535d9fc70 | ||
|
|
9c93e38aff | ||
|
|
bfde5dfe1a | ||
|
|
d8eb3c8984 | ||
|
|
1cee2b67a6 | ||
|
|
82529ce56a | ||
|
|
70f30f0713 | ||
|
|
24ebb0bf8a | ||
|
|
d7372c7c55 | ||
|
|
f7bcf71020 | ||
|
|
72146afe48 | ||
|
|
9bcdb42edb | ||
|
|
16e0827991 | ||
|
|
863a6fb0dc | ||
|
|
5799ffe79b | ||
|
|
a8ebab7fcb | ||
|
|
e0ec27ad07 | ||
|
|
85220105b0 | ||
|
|
9afdb24a82 | ||
|
|
3c7ab13995 | ||
|
|
31b72f3bd3 | ||
|
|
ee5aada1b9 | ||
|
|
9e15044f6a | ||
|
|
9d891dae55 |
149
.github/workflows/release.yml
vendored
149
.github/workflows/release.yml
vendored
@@ -7,93 +7,94 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
PLUGIN_NAME: share-to-notionnext # Change this to match the id of your plugin.
|
PLUGIN_NAME: share-to-notionnext # Change this to match the id of your plugin.
|
||||||
|
CHANGELOG_FILENAME: CHANGELOG.md
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: release
|
name: release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Use Node.js
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: "18"
|
node-version: "18"
|
||||||
|
|
||||||
- name: Generate changelog
|
# - name: Generate changelog
|
||||||
id: changelog
|
# id: changelog
|
||||||
uses: saadmk11/changelog-ci@v1.1.2
|
# uses: saadmk11/changelog-ci@v1.1.2
|
||||||
with:
|
# with:
|
||||||
github_token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
# github_token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
release_version: ${{ github.ref }}
|
# release_version: ${{ github.ref }}
|
||||||
changelog_filename: CHANGELOG.md
|
# changelog_filename: CHANGELOG.md
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
id: build
|
id: build
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
mkdir ${{ env.PLUGIN_NAME }}
|
mkdir ${{ env.PLUGIN_NAME }}
|
||||||
cp main.js manifest.json ${{ env.PLUGIN_NAME }}
|
cp main.js manifest.json ${{ env.PLUGIN_NAME }}
|
||||||
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
|
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
|
||||||
ls
|
ls
|
||||||
echo "tag_name=$(git tag --sort version:refname | tail -n 1)" >> $GITHUB_OUTPUT
|
echo "tag_name=$(git tag --sort version:refname | tail -n 1)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
VERSION: ${{ github.ref }}
|
VERSION: ${{ github.ref }}
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ github.ref }}
|
tag_name: ${{ github.ref }}
|
||||||
release_name: ${{ github.ref }}
|
release_name: ${{ github.ref }}
|
||||||
draft: false
|
body_path: ${{ env.CHANGELOG_FILENAME }}
|
||||||
prerelease: false
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
|
||||||
- name: Upload zip file
|
- name: Upload zip file
|
||||||
id: upload-zip
|
id: upload-zip
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
with:
|
with:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
asset_path: ./${{ env.PLUGIN_NAME }}.zip
|
asset_path: ./${{ env.PLUGIN_NAME }}.zip
|
||||||
asset_name: ${{ env.PLUGIN_NAME }}-${{ steps.build.outputs.tag_name }}.zip
|
asset_name: ${{ env.PLUGIN_NAME }}-${{ steps.build.outputs.tag_name }}.zip
|
||||||
asset_content_type: application/zip
|
asset_content_type: application/zip
|
||||||
|
|
||||||
- name: Upload main.js
|
- name: Upload main.js
|
||||||
id: upload-main
|
id: upload-main
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
with:
|
with:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
asset_path: ./main.js
|
asset_path: ./main.js
|
||||||
asset_name: main.js
|
asset_name: main.js
|
||||||
asset_content_type: text/javascript
|
asset_content_type: text/javascript
|
||||||
|
|
||||||
- name: Upload manifest.json
|
- name: Upload manifest.json
|
||||||
id: upload-manifest
|
id: upload-manifest
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
with:
|
with:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
asset_path: ./manifest.json
|
asset_path: ./manifest.json
|
||||||
asset_name: manifest.json
|
asset_name: manifest.json
|
||||||
asset_content_type: application/json
|
asset_content_type: application/json
|
||||||
|
|
||||||
- name: Upload markdown template
|
- name: Upload markdown template
|
||||||
id: upload-md
|
id: upload-md
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
with:
|
with:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
asset_path: ./obsidian_template.md
|
asset_path: ./obsidian_template.md
|
||||||
asset_name: template.md
|
asset_name: template.md
|
||||||
asset_content_type: text/markdown
|
asset_content_type: text/markdown
|
||||||
|
|
||||||
# - name: Upload styles.css
|
# - name: Upload styles.css
|
||||||
# id: upload-css
|
# id: upload-css
|
||||||
|
|||||||
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,19 +1,7 @@
|
|||||||
# Changelog v2.2.0
|
## Fix
|
||||||
|
|
||||||
## Feature
|
- Fix a gif link in README.md
|
||||||
|
|
||||||
- add the support for the customised properties of general databases
|
## Features
|
||||||
- 增加对普通数据库自定义属性的支持
|
|
||||||
|
|
||||||
- support
|
- Change the success notice colour to green
|
||||||
- [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**)
|
|
||||||
|
|||||||
492
README.md
492
README.md
@@ -3,47 +3,253 @@
|
|||||||
[](https://github.com/jxpeng98/obsidian-to-NotionNext/actions/workflows/test.yml)
|
[](https://github.com/jxpeng98/obsidian-to-NotionNext/actions/workflows/test.yml)
|
||||||
[](https://github.com/jxpeng98/obsidian-to-NotionNext/actions/workflows/release.yml)
|
[](https://github.com/jxpeng98/obsidian-to-NotionNext/actions/workflows/release.yml)
|
||||||
[](https://GitHub.com/jxpeng98/obsidian-to-NotionNext/releases/)
|
[](https://GitHub.com/jxpeng98/obsidian-to-NotionNext/releases/)
|
||||||
[](https://github.com/jxpeng98/obsidian-to-NotionNext/releases/)
|
[](https://github.com/jxpeng98/obsidian-to-NotionNext/releases/)
|
||||||
|
|
||||||
[//]: # ([](https://GitHub.com/jxpeng98/obsidian-to-NotionNext/releases/))
|
[//]: # ([](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.**
|
||||||
|
|
||||||
**现在支持NotionNext和普通Notion数据库,可自定义数据库列表。**
|
**现在支持NotionNext和普通Notion数据库,可自定义数据库列表。**
|
||||||
|
|
||||||
|
## Precautions
|
||||||
|
|
||||||
|
### For customised database users
|
||||||
|
|
||||||
|
**⚠️⚠️⚠️: The existing 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版本,你需要重新创建自定义数据库。新版本有一个新的数据库结构,旧的数据库结构无法构建索引。**
|
||||||
|
|
||||||
## TODO List
|
## TODO List
|
||||||
|
|
||||||
- [x] Support custom properties for Notion General database. 支持自定义属性
|
- [x] ~~Modify the Edit function for the custom properties. 改进自定义属性的编辑功能~~
|
||||||
- [ ] Support group upload with one click 支持一键多数据库上传
|
- [ ] Support group upload with one click 支持一键多数据库上传
|
||||||
- [x] Support preview for database details in plugin settings. 支持预览数据库详情
|
- [x] ~~Support custom properties for Notion General database. 支持自定义属性~~
|
||||||
- [x] Support edit for database details in plugin settings. 支持编辑数据库详情
|
- [x] ~~Support preview for database details in plugin settings. 支持预览数据库详情~~
|
||||||
|
- [x] ~~Support edit for database details in plugin settings. 支持编辑数据库详情~~
|
||||||
|
|
||||||
## Update
|
## How to use
|
||||||
|
|
||||||
### 2.2.0 (Big Update)
|
If you want to use this plugin, you need to follow the following steps to set up the plugin. The steps can be divided into two parts: setting up the Notion API and setting up the plugin in Obsidian.
|
||||||
|
|
||||||
- add the support for custom properties in the Notion General database. 支持自定义属性
|
### 1. Setting up the Notion API
|
||||||
- [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**)
|
|
||||||
|
|
||||||

|
1). Go to [Notion API](https://www.notion.com/my-integrations) to create a new integration, and **copy the token**.
|
||||||
- Once you create the properties, you can preview the database details in the plugin settings.
|
|
||||||

|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2). Create a database in your Notion workspace.
|
||||||
|
|
||||||
|
Open Notion, click top-left `Create` a new page` -> You can give a title for the page and press "/" Select 'Database - Full page'.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Rename the database properties to `title` and `tags`.
|
||||||
|
**⚠️⚠️`title` is the title column! `tags` is lower case⚠️⚠️**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
3). Add the Notion API integration.
|
||||||
|
|
||||||
|
Click the right-top '...' -> connections -> connect to -> find the integration you created and connect it.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
4). Publish the database to the public.
|
||||||
|
Click the 'Share' -> 'Publish' -> 'Publish' -> **copy the database id from the URL**.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 2. Setting up the plugin in Obsidian
|
||||||
|
|
||||||
|
1). Go to Obsidian settings -> community plugins -> search 'NotionNext' -> install it.
|
||||||
|

|
||||||
|
|
||||||
|
2). Open the plugin settings and create a new database.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 3. Create a database
|
||||||
|
|
||||||
|
**You can create three types of databases:**
|
||||||
|
|
||||||
|
#### 1️⃣ General database
|
||||||
|
|
||||||
|
General database is the default database, which only has the `title` and `tags` columns. **⚠️⚠️`title` and `tags` are lowercase⚠️⚠️**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The general is as follows:
|
||||||
|
|
||||||
|
- Full Name: the full name that you would like to give to the database.
|
||||||
|
- Abbreviate Name: the abbreviation that you would like to give to the database.
|
||||||
|
- Notion tags sync: whether you want to sync the tags column to Notion.
|
||||||
|
- Customise title property: whether you want to change the `title` to another name (e.g., `name`).
|
||||||
|
- Notion API token: the token you copied from the Notion API page.
|
||||||
|
- Notion Database ID: the database ID you copied from the Notion database URL. (e.g., only copy `7158cd3f70ce4f60afd9da5bdf74fd0c` between `site/` and `?`. `https://jxpeng.notion.site/7158cd3f70ce4f60afd9da5bdf74fd0c?v=380317ac5373sadasdas3c13e618f&pvs=4**`)
|
||||||
|
|
||||||
|
After setting, it should look like this:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Once you click `save`, the new database will be created in the plugin settings and display in the detabase list.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### 2️⃣ NotionNext database
|
||||||
|
|
||||||
|
If you use [NotionNext](https://github.com/tangly1024/NotionNext) to set up your website, you can use the NotionNext database. (**All the properties are in lowercase, and you do not need to change the properties**)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Like the general database, you need to fill in the following information:
|
||||||
|
|
||||||
|
- Full Name: the full name that you would like to give to the database.
|
||||||
|
- Abbreviate Name: the abbreviation that you would like to give to the database.
|
||||||
|
- Notion API token: the token you copied from the Notion API page.
|
||||||
|
- Notion Database ID: the database ID you copied from the Notion database URL.
|
||||||
|
|
||||||
|
#### 3️⃣ Custom database
|
||||||
|
|
||||||
|
The custom database is purely customised, and you can customise the properties you want to sync. (**All the properties are in lowercase, and you do not need to change the properties**)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The basic information is identical to the general database and NotionNext database. You need to fill in the following information:
|
||||||
|
|
||||||
|
- Full Name: the full name that you would like to give to the database.
|
||||||
|
- Abbreviate Name: the abbreviation that you would like to give to the database.
|
||||||
|
- Notion API token: the token you copied from the Notion API page.
|
||||||
|
- Notion Database ID: the database ID you copied from the Notion database URL.
|
||||||
|
|
||||||
|
After adding the information, You can click `Add New Property` to add the properties you want to sync. There is no limit to the number of properties you can add.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**⚠️⚠️⚠️**: **`Title column` is the main property in the Notion database, which has the open button to open the underlying page.** You can select the type of all other properties. **⚠️⚠️⚠️**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
According to the previously shown database, you can use `title` as the `Title column`, and `Tags` as the property 1.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Until now, you have set up the plugin in Obsidian. You can start syncing your notes to Notion.**
|
||||||
|
|
||||||
|
### 4. Start syncing
|
||||||
|
|
||||||
|
Create a new note in Obsidian, and fill in the front matter with the properties you want to sync.
|
||||||
|
|
||||||
|
#### 1️⃣ note for general database
|
||||||
|
|
||||||
|
For example, we can create a test note with the following front matter:
|
||||||
|
|
||||||
|
``` markdown
|
||||||
|
---
|
||||||
|
title: test
|
||||||
|
tags: [test, web]
|
||||||
---
|
---
|
||||||
|
|
||||||
## Acknowledgement
|
This is a test file.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
After creating the note, you can click the `Share to NotionNext` button on the left sidebar to sync the note to Notion.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### 2️⃣ note for NotionNext database
|
||||||
|
|
||||||
|
We use the following front matter for the NotionNext database:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
---
|
||||||
|
title: test-notionnext
|
||||||
|
titleicon: 📎
|
||||||
|
date: 2023-07-23
|
||||||
|
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg
|
||||||
|
type: Post
|
||||||
|
slug: test
|
||||||
|
status: Draft
|
||||||
|
category: test
|
||||||
|
summary: this is a summary for test post
|
||||||
|
icon: fa-solid fa-camera
|
||||||
|
password: "1234"
|
||||||
|
tags:
|
||||||
|
- test
|
||||||
|
- web
|
||||||
|
NotionID-pengjiaxin: 8ba573de-8fdf-4681-b063-c39d26e7860e
|
||||||
|
---
|
||||||
|
|
||||||
|
this is a test file
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### 3️⃣ note for custom database
|
||||||
|
|
||||||
|
##### sync title and tags
|
||||||
|
|
||||||
|
Use the previously created general database and rename `title` to `Name` and `tags` to `Tags` in Notion.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The front matter for the custom database is as follows:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
---
|
||||||
|
Name: test-custom
|
||||||
|
Tags:
|
||||||
|
- test
|
||||||
|
- web
|
||||||
|
---
|
||||||
|
|
||||||
|
This is a test file.
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
##### sync more properties
|
||||||
|
|
||||||
|
Add more property to the custom database. For example, we can add a `summary` and `date` property to the custom database.
|
||||||
|
|
||||||
|
1). Click `Edit` in the plugin settings.
|
||||||
|

|
||||||
|
2). Click `Add` and add the `summary` and `date` property.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
3). After adding the properties, you can see the properties in the plugin settings.
|
||||||
|

|
||||||
|
4). Add the `summary` and `date` in Notion
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
5). Create a new note with the `summary` and `date` property.
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
---
|
||||||
|
Name: test-custom-more
|
||||||
|
Tags:
|
||||||
|
- test
|
||||||
|
- web
|
||||||
|
summary: this is a summary for test custom
|
||||||
|
date: 2022-05-03
|
||||||
|
---
|
||||||
|
|
||||||
|
This is a test file.
|
||||||
|
```
|
||||||
|
|
||||||
|
6). Sync the note to Notion.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Acknowledgment
|
||||||
|
|
||||||
Thanks to the [original author](https://github.com/EasyChris/obsidian-to-notion) for developing such a useful plugin that can synchronize Obsidian to Notion. However, the original repository can only sync Name and Tag information. For those like me who use [NotionNext](https://github.com/tangly1024/NotionNext) to set up their website, this presents some limitations. Every time I import, I need to make a lot of modifications.
|
Thanks to the [original author](https://github.com/EasyChris/obsidian-to-notion) for developing such a useful plugin that can synchronize Obsidian to Notion. However, the original repository can only sync Name and Tag information. For those like me who use [NotionNext](https://github.com/tangly1024/NotionNext) to set up their website, this presents some limitations. Every time I import, I need to make a lot of modifications.
|
||||||
|
|
||||||
@@ -51,238 +257,7 @@ Thus, based on the [original author's work](https://github.com/EasyChris/obsidia
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Archive Update
|
<details> <summary> Original README.md </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. 增加插件设置中数据库详情的预览和编辑功能。
|
|
||||||

|
|
||||||
- Preview:
|
|
||||||

|
|
||||||
|
|
||||||
- Edit:
|
|
||||||

|
|
||||||
|
|
||||||
### 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)
|
|
||||||
- 一部分是数据库列表:你可以添加新的数据库或者删除数据库。
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- You can add more databases in the plugin settings.
|
|
||||||
- 你可以在插件设置中添加更多的数据库。
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- You can sync one note to multiple databases.
|
|
||||||
- 你可以将一个笔记同步到多个数据库中。
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
**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.**)
|
|
||||||
|
|
||||||

|
|
||||||
Like this:
|
|
||||||

|
|
||||||
|
|
||||||
- Add a switch button to control whether display the setting tabs in the plugin settings for both NotionNext and Notion General databases.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### 0.2.6
|
|
||||||
|
|
||||||
- Add a switch button to control whether to show the upload command in the command palette.
|
|
||||||
|
|
||||||
<!-- 
|
|
||||||
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.
|
|
||||||
|
|
||||||
 -->
|
|
||||||
|
|
||||||
### 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.**
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### 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.
|
|
||||||
|
|
||||||
## How to Use
|
|
||||||
|
|
||||||
### Precautions
|
|
||||||
|
|
||||||
For now, this plugin is exclusively for [NotionNext](https://github.com/tangly1024/NotionNext). If you're not using this template, you'll keep receiving `error 400`.
|
|
||||||
|
|
||||||
For those without a NotionNext requirement, please use the original [Obsidian-to-notion](https://github.com/EasyChris/obsidian-to-notion).
|
|
||||||
|
|
||||||
### Pre-Installation Steps
|
|
||||||
|
|
||||||
Before installing the plugin, you must have set up the following:
|
|
||||||
|
|
||||||
1. Your NotionNext database.
|
|
||||||
2. According to the original author's readme.md, set up the Notion API, and it should already be associated with your NotionNext repository.
|
|
||||||
3. NotionNext Database ID
|
|
||||||
4. Your NotionNext database should have the following contents:
|
|
||||||
- type
|
|
||||||
- title
|
|
||||||
- slug
|
|
||||||
- category
|
|
||||||
- tags
|
|
||||||
- date
|
|
||||||
- status
|
|
||||||
- summary
|
|
||||||
- password
|
|
||||||
- icon
|
|
||||||
|
|
||||||
From version 0.0.6, I also add the following contents:
|
|
||||||
- titleicon: the unique icon for each post, it can only support emoji currently.
|
|
||||||
- cover url: the cover image for each post, it should be end with a type of image, such as .jpg, .png, .gif, etc.
|
|
||||||
|
|
||||||
**If you've directly copied the NotionNext template, these contents should already exist. I've made changes to this plugin based on the original author's work. All you need to ensure is that your database has the above content, and every letter is in lowercase!!!**
|
|
||||||
|
|
||||||
**⚠️⚠️⚠️: All headers are in lowercase!!! The order doesn't matter!**
|
|
||||||
|
|
||||||
### Plugin Installation
|
|
||||||
|
|
||||||
#### Install via Community Plugins
|
|
||||||
|
|
||||||
Open `Obsidian settings -> Community Plugins -> Browse -> NotionNext -> Share to NotionNext`
|
|
||||||
|
|
||||||
#### Mannually Install
|
|
||||||
|
|
||||||
1. Close Obsidian.
|
|
||||||
2. Download the plugin file from Release and unzip it into your Obsidian plugin directory.
|
|
||||||
3. Re-open Obsidian, go to settings, and enable the plugin.
|
|
||||||
4. In the settings, find Obsidian to NotionNext, and enter your NotionNext Database ID and API token.
|
|
||||||
|
|
||||||
### How to Use
|
|
||||||
|
|
||||||
### Using the Plugin
|
|
||||||
|
|
||||||
In the repository, I have uploaded a template which you can directly copy into your template folder. After that, use Obsidian's template feature to create a new note with one click.
|
|
||||||
|
|
||||||
If you don't want to use the template, you can also directly create a new file in Obsidian and then copy the content below. Then save it.
|
|
||||||
|
|
||||||
```markdown
|
|
||||||
---
|
|
||||||
# default value has been set.
|
|
||||||
# for any unwanted value, you can delete it or set it to empty.
|
|
||||||
# for example, if you donot want to set password, you can delete password: "1234" or set it to password: ""
|
|
||||||
# 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。
|
|
||||||
# 例如你不需要密码选项,你可以将password: "1234"删除,或者将它设置为空。
|
|
||||||
# !!!!!!!!!!!!
|
|
||||||
# 现在阶段一定不要修改表头的名字, please do not change the name of the header in YAML front matter
|
|
||||||
# !!!!!!!!!!!!
|
|
||||||
titleicon: 📎 # emoji icon, default is 📜, 默认是📜
|
|
||||||
date: 2023-07-23 # default is today, 默认是今天。 Format is YYYY-MM-DD, 格式是YYYY-MM-DD
|
|
||||||
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty, 默认是空
|
|
||||||
type: Post # Post or Page, default is Post, 默认是Post
|
|
||||||
slug: test # slug for url, default is empty, 默认是空
|
|
||||||
stats: Draft # Draft, Invisible, Published, default is Draft, 默认是Draft
|
|
||||||
category: test # default is 'Obsidian', 默认是'Obsidian'
|
|
||||||
summary: this is a summary for test post # default is empty, 默认是空
|
|
||||||
icon: fa-solid fa-camera # you can ignore this, default is empty, 默认是空,可直接删除
|
|
||||||
password: "1234" # if you donot want to set password, you can delete this line, default is empty, 默认是空,可直接删除
|
|
||||||
# 现在必须开启tags选项,否则会报错
|
|
||||||
tags:
|
|
||||||
- test # tags for post
|
|
||||||
- web # add more tags if you want
|
|
||||||
---
|
|
||||||
|
|
||||||
Contents Below
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Usage of the template is as follows:
|
|
||||||

|
|
||||||
|
|
||||||
**Plugin preview is shown below**
|
|
||||||

|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Original README.md**
|
|
||||||
|
|
||||||
Many Thanks for the original author's work. I've only made some changes to the original author's work. If you find this plugin useful, please give the [original author](https://github.com/EasyChris/obsidian-to-notion) a star.
|
Many Thanks for the original author's work. I've only made some changes to the original author's work. If you find this plugin useful, please give the [original author](https://github.com/EasyChris/obsidian-to-notion) a star.
|
||||||
|
|
||||||
@@ -456,10 +431,6 @@ node update-version.js
|
|||||||
./release.sh
|
./release.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Thanks
|
# Thanks
|
||||||
[Development Process | Obsidian Plugin Development Documentation](https://luhaifeng666.github.io/obsidian-plugin-docs-zh/zh/getting-started/development-workflow.html)
|
[Development Process | Obsidian Plugin Development Documentation](https://luhaifeng666.github.io/obsidian-plugin-docs-zh/zh/getting-started/development-workflow.html)
|
||||||
@@ -476,3 +447,6 @@ node update-version.js
|
|||||||
|
|
||||||
# License
|
# License
|
||||||
GNU GPLv3
|
GNU GPLv3
|
||||||
|
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "share-to-notionnext",
|
"id": "share-to-notionnext",
|
||||||
"name": "Share to NotionNext",
|
"name": "Share to NotionNext",
|
||||||
"version": "2.2.0",
|
"version": "2.3.3",
|
||||||
"minAppVersion": "0.0.1",
|
"minAppVersion": "0.0.1",
|
||||||
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
||||||
"author": "EasyChris, jxpeng98",
|
"author": "EasyChris, jxpeng98",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ date: 2023-07-23 # default is today, 默认是今天。 Format is YYYY-MM-DD
|
|||||||
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty, 默认是空
|
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty, 默认是空
|
||||||
type: Post # Post or Page, default is Post, 默认是Post
|
type: Post # Post or Page, default is Post, 默认是Post
|
||||||
slug: test # slug for url, default is empty, 默认是空
|
slug: test # slug for url, default is empty, 默认是空
|
||||||
stats: Draft # Draft, Invisible, Published, default is Draft, 默认是Draft
|
status: Draft # Draft, Invisible, Published, default is Draft, 默认是Draft
|
||||||
category: test # default is 'Obsidian', 默认是'Obsidian'
|
category: test # default is 'Obsidian', 默认是'Obsidian'
|
||||||
summary: this is a summary for test post # default is empty, 默认是空
|
summary: this is a summary for test post # default is empty, 默认是空
|
||||||
icon: fa-solid fa-camera # you can ignore this, default is empty, 默认是空,可直接删除
|
icon: fa-solid fa-camera # you can ignore this, default is empty, 默认是空,可直接删除
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "share-to-notionnext",
|
"name": "share-to-notionnext",
|
||||||
"version": "2.2.0",
|
"version": "2.3.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -23,15 +23,18 @@ export const en = {
|
|||||||
NotionAPIDesc: "Generate from https://www.notion.so/my-integrations",
|
NotionAPIDesc: "Generate from https://www.notion.so/my-integrations",
|
||||||
NotionAPIText: "Enter your Notion API Token",
|
NotionAPIText: "Enter your Notion API Token",
|
||||||
DatabaseID: "Database ID",
|
DatabaseID: "Database ID",
|
||||||
|
DatabaseIDDesc: "Collect from the top-right Share --> Publish",
|
||||||
DatabaseIDText: "Enter your Database ID",
|
DatabaseIDText: "Enter your Database ID",
|
||||||
BannerUrl: "Banner url (optional)",
|
BannerUrl: "Banner url (optional)",
|
||||||
BannerUrlDesc:
|
BannerUrlDesc:
|
||||||
"Default is empty, if you want to show a banner, please enter the url (like: https://minioapi.pjx.ac.cn/img1/2023/11/b7b40a0724e93b7d7ab494bb3b8a2da8.png)",
|
"Default is empty, if you want to show a banner, please enter the url (like: https://abc.com/b.png)",
|
||||||
BannerUrlText: "Enter your banner url",
|
BannerUrlText: "Enter your banner url",
|
||||||
NotionUser: "Notion ID (username, optional)",
|
NotionUser: "Notion ID (username, optional)",
|
||||||
NotionUserDesc:
|
NotionUserDesc:
|
||||||
"Collect from share link likes:https://username.notion.site. Your notion id is [username]",
|
"Collect from share link likes:https://username.notion.site. Your notion id is [username]",
|
||||||
NotionUserText: "Enter your notion ID",
|
NotionUserText: "Enter your notion ID",
|
||||||
|
NotionLinkDisplay: "Notion Link Display",
|
||||||
|
NotionLinkDisplayDesc: "Default is ON, if you want to hide the link in the front matter, please turn it off",
|
||||||
NotionGeneralSettingHeader: "General Notion Database Settings",
|
NotionGeneralSettingHeader: "General Notion Database Settings",
|
||||||
NotionGeneralButton: "Notion General Sync",
|
NotionGeneralButton: "Notion General Sync",
|
||||||
NotionGeneralButtonDesc: "Open this option, Sync to Notion General Database command will be displayed in the command palette (default: ON)",
|
NotionGeneralButtonDesc: "Open this option, Sync to Notion General Database command will be displayed in the command palette (default: ON)",
|
||||||
@@ -45,24 +48,32 @@ export const en = {
|
|||||||
NotionCustomValues: "Customise values property",
|
NotionCustomValues: "Customise values property",
|
||||||
NotionCustomValuesDesc: "Modify the column name of the Notion database,one per line",
|
NotionCustomValuesDesc: "Modify the column name of the Notion database,one per line",
|
||||||
NotionCustomValuesText: "Enter all properties that you want to sync",
|
NotionCustomValuesText: "Enter all properties that you want to sync",
|
||||||
NotYetFinish:
|
NotYetFinish: "Not finished. This function will be available in the next version",
|
||||||
"Not finished. This function will be available in the next version",
|
|
||||||
PlaceHolder: "Enter database Name",
|
PlaceHolder: "Enter database Name",
|
||||||
"notion-logo": "Share to NotionNext",
|
"notion-logo": "Share to NotionNext",
|
||||||
"sync-success": "Sync to NotionNext success: \n",
|
"sync-preffix": "Sync to ",
|
||||||
"sync-fail": "Sync to NotionNext fail: \n",
|
"sync-success": "success",
|
||||||
|
"sync-fail": "failed",
|
||||||
"open-notion": "Please open the file that needs to be synchronized",
|
"open-notion": "Please open the file that needs to be synchronized",
|
||||||
"config-secrets-notion-api":
|
"config-secrets-notion-api":
|
||||||
"Please set up the notion API in the settings tab.",
|
"Please set up the notion API in the settings tab.",
|
||||||
"config-secrets-database-id":
|
"config-secrets-database-id":
|
||||||
"Please set up the database id in the settings tab.",
|
"Please set up the database id in the settings tab.",
|
||||||
"set-tags-fail":
|
"set-tags-fail":
|
||||||
"Set tags fail,please check the frontmatter of the file or close the tag switch in the settings tab.",
|
"Set tags fail,please check the frontmatter of the file or close the tag switch in the settings tab.",
|
||||||
NNonMissing:
|
NNonMissing:
|
||||||
"The 'NNon' property is missing in the settings. Please set it up.",
|
"The 'NNon' property is missing in the settings. Please set it up.",
|
||||||
"set-api-id":
|
"set-api-id":
|
||||||
"Please set up the notion API and database ID in the settings tab.",
|
"Please set up the notion API and database ID in the settings tab.",
|
||||||
NotionCustomSettingHeader: "Notion Custom Database Settings",
|
NotionCustomSettingHeader: "Notion Custom Database Settings",
|
||||||
NotionCustomButton: "Notion Customised command switch",
|
NotionCustomButton: "Notion Customised command switch",
|
||||||
NotionCustomButtonDesc: "Open this option, Sync to Notion Customised Database command will be displayed in the command palette",
|
NotionCustomButtonDesc: "Open this option, Sync to Notion Customised Database command will be displayed in the command palette",
|
||||||
|
CustomPropertyName: "Property Name",
|
||||||
|
CustomPropertyFirstColumn: "Title Column",
|
||||||
|
CustomPropertyFirstColumnDesc: "The title of the page, must be the first property",
|
||||||
|
CustomProperty: "Property",
|
||||||
|
AddCustomProperty: "Add Custom Property",
|
||||||
|
AddNewProperty: "Add New Property",
|
||||||
|
AddNewPropertyDesc: "Add new property match with your notion database",
|
||||||
|
CopyErrorMessage: "Auto copy failed, please copy it manually",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,16 @@ export const ja = {
|
|||||||
NotionAPIDesc: "https://www.notion.so/my-integrations から生成してください",
|
NotionAPIDesc: "https://www.notion.so/my-integrations から生成してください",
|
||||||
NotionAPIText: "Notion API トークンを入力",
|
NotionAPIText: "Notion API トークンを入力",
|
||||||
DatabaseID: "データベースID",
|
DatabaseID: "データベースID",
|
||||||
|
DatabaseIDDesc: "右上の共有 --> 公開から取得してください",
|
||||||
DatabaseIDText: "データベースIDを入力",
|
DatabaseIDText: "データベースIDを入力",
|
||||||
BannerUrl: "バナーのURL(任意)",
|
BannerUrl: "バナーのURL(任意)",
|
||||||
BannerUrlDesc: "デフォルトは空白です。バナーを表示したい場合は、URLを入力してください(例:https://minioapi.pjx.ac.cn/img1/2023/11/b7b40a0724e93b7d7ab494bb3b8a2da8.png)",
|
BannerUrlDesc: "デフォルトは空白です。バナーを表示したい場合は、URLを入力してください(例:https://abc.com/b.png)",
|
||||||
BannerUrlText: "バナーのURLを入力",
|
BannerUrlText: "バナーのURLを入力",
|
||||||
NotionUser: "Notion ID(ユーザー名、任意)",
|
NotionUser: "Notion ID(ユーザー名、任意)",
|
||||||
NotionUserDesc: "共有リンクから取得(例:https://username.notion.site)。Notion IDは[username]です",
|
NotionUserDesc: "共有リンクから取得(例:https://username.notion.site)。Notion IDは[username]です",
|
||||||
NotionUserText: "Notion IDを入力",
|
NotionUserText: "Notion IDを入力",
|
||||||
|
NotionLinkDisplay: "Notionリンク表示",
|
||||||
|
NotionLinkDisplayDesc: "デフォルトはONです。front matterにリンクを非表示にしたい場合は、オフにしてください",
|
||||||
NotionGeneralSettingHeader: "一般的なNotionデータベース設定",
|
NotionGeneralSettingHeader: "一般的なNotionデータベース設定",
|
||||||
NotionGeneralButton: "一般的なNotion同期",
|
NotionGeneralButton: "一般的なNotion同期",
|
||||||
NotionGeneralButtonDesc: "このオプションを開くと、一般的なNotionデータベース同期コマンドがコマンドパレットに表示されます(デフォルト:ON)",
|
NotionGeneralButtonDesc: "このオプションを開くと、一般的なNotionデータベース同期コマンドがコマンドパレットに表示されます(デフォルト:ON)",
|
||||||
@@ -57,4 +60,12 @@ export const ja = {
|
|||||||
NotionCustomSettingHeader: "Notionカスタムデータベース設定",
|
NotionCustomSettingHeader: "Notionカスタムデータベース設定",
|
||||||
NotionCustomButton: "Notionカスタマイズコマンドの切り替え",
|
NotionCustomButton: "Notionカスタマイズコマンドの切り替え",
|
||||||
NotionCustomButtonDesc: "このオプションを開くと、Notionカスタムデータベース同期コマンドがコマンドパレットに表示されます",
|
NotionCustomButtonDesc: "このオプションを開くと、Notionカスタムデータベース同期コマンドがコマンドパレットに表示されます",
|
||||||
|
CustomPropertyName: "カスタムプロパティ名",
|
||||||
|
CustomPropertyFirstColumn: "最初の列のカスタムプロパティ名",
|
||||||
|
CustomPropertyFirstColumnDesc: "最初の列のカスタムプロパティ名を入力してください",
|
||||||
|
CustomProperty: "カスタムプロパティ",
|
||||||
|
AddCustomProperty: "カスタムプロパティを追加",
|
||||||
|
AddNewProperty: "新しいプロパティを追加",
|
||||||
|
AddNewPropertyDesc: "新しいプロパティを追加してください",
|
||||||
|
CopyErrorMessage: "自動コピーに失敗しました",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,15 +23,18 @@ export const zh = {
|
|||||||
NotionAPIDesc: "从 https://www.notion.so/my-integrations 生成",
|
NotionAPIDesc: "从 https://www.notion.so/my-integrations 生成",
|
||||||
NotionAPIText: "输入你的 Notion API 令牌",
|
NotionAPIText: "输入你的 Notion API 令牌",
|
||||||
DatabaseID: "数据库 ID",
|
DatabaseID: "数据库 ID",
|
||||||
|
DatabaseIDDesc: "从右上角的分享 --> 发布中获取",
|
||||||
DatabaseIDText: "输入你的数据库 ID",
|
DatabaseIDText: "输入你的数据库 ID",
|
||||||
BannerUrl: "封面图片地址(可选)",
|
BannerUrl: "封面图片地址(可选)",
|
||||||
BannerUrlDesc:
|
BannerUrlDesc:
|
||||||
"默认为空,如果你想显示封面图片,请输入图片地址(例如:https://minioapi.pjx.ac.cn/img1/2023/11/b7b40a0724e93b7d7ab494bb3b8a2da8.png)",
|
"默认为空,如果你想显示封面图片,请输入图片地址(例如:https://abc.com/b.png)",
|
||||||
BannerUrlText: "输入你的封面图片地址",
|
BannerUrlText: "输入你的封面图片地址",
|
||||||
NotionUser: "Notion ID(用户名,可选)",
|
NotionUser: "Notion ID(用户名,可选)",
|
||||||
NotionUserDesc:
|
NotionUserDesc:
|
||||||
"数据库分享链接类似:https://username.notion.site/。你的 Notion ID 是 [username]",
|
"数据库分享链接类似:https://username.notion.site/。你的 Notion ID 是 [username]",
|
||||||
NotionUserText: "输入你的 Notion ID",
|
NotionUserText: "输入你的 Notion ID",
|
||||||
|
NotionLinkDisplay: "Notion 链接显示",
|
||||||
|
NotionLinkDisplayDesc: "默认开启,如果你不想在front matter中显示链接,请关闭",
|
||||||
NotionGeneralSettingHeader: "普通 Notion 数据库设置",
|
NotionGeneralSettingHeader: "普通 Notion 数据库设置",
|
||||||
NotionGeneralButton: "普通数据库同步",
|
NotionGeneralButton: "普通数据库同步",
|
||||||
NotionGeneralButtonDesc: "打开此选项,同步到普通数据库命令将显示在命令面板中(默认:开)",
|
NotionGeneralButtonDesc: "打开此选项,同步到普通数据库命令将显示在命令面板中(默认:开)",
|
||||||
@@ -60,4 +63,12 @@ export const zh = {
|
|||||||
NotionCustomSettingHeader: "Notion 自定义数据库设置",
|
NotionCustomSettingHeader: "Notion 自定义数据库设置",
|
||||||
NotionCustomButton: "Notion 自定义数据库同步命令开关",
|
NotionCustomButton: "Notion 自定义数据库同步命令开关",
|
||||||
NotionCustomButtonDesc: "打开此选项,同步到自定义数据库命令将显示在命令面板中",
|
NotionCustomButtonDesc: "打开此选项,同步到自定义数据库命令将显示在命令面板中",
|
||||||
|
CustomPropertyName: "自定义属性名",
|
||||||
|
CustomPropertyFirstColumn: "第一列属性名",
|
||||||
|
CustomPropertyFirstColumnDesc: "第一列必须为标题属性名",
|
||||||
|
CustomProperty: "自定义属性",
|
||||||
|
AddCustomProperty: "添加自定义属性",
|
||||||
|
AddNewProperty: "添加新属性",
|
||||||
|
AddNewPropertyDesc: "添加一个和Notion数据库匹配的新属性",
|
||||||
|
CopyErrorMessage: "复制链接失败,请手动复制",
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/main.ts
42
src/main.ts
@@ -55,33 +55,33 @@ 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,160 +0,0 @@
|
|||||||
import {App, Modal, Setting} from "obsidian";
|
|
||||||
import ObsidianSyncNotionPlugin from "../main";
|
|
||||||
import {ObsidianSettingTab} from "./settingTabs";
|
|
||||||
|
|
||||||
export class CustomModal extends Modal {
|
|
||||||
propertyLines: Setting[] = []; // Store all property line settings
|
|
||||||
properties: { customName: string, customType: string }[] = []; // Array to store property values and types
|
|
||||||
plugin: ObsidianSyncNotionPlugin;
|
|
||||||
settingTab: ObsidianSettingTab;
|
|
||||||
|
|
||||||
constructor(app: App) {
|
|
||||||
super(app);
|
|
||||||
}
|
|
||||||
|
|
||||||
createPropertyLine(containerEl: HTMLElement): void {
|
|
||||||
const propertyIndex = this.properties.length;
|
|
||||||
this.properties.push({customName: "", customType: ""}); // Initialize with empty values
|
|
||||||
|
|
||||||
const propertyLine = new Setting(containerEl)
|
|
||||||
|
|
||||||
if (propertyIndex === 0) {
|
|
||||||
propertyLine
|
|
||||||
.setName("Title")
|
|
||||||
.setDesc("The title of the page, must be the first property")
|
|
||||||
|
|
||||||
propertyLine.addText((text) => {
|
|
||||||
text
|
|
||||||
.setPlaceholder("Property name")
|
|
||||||
.setValue("")
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.properties[propertyIndex].customName = value; // Update the customValue of the specific property
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
propertyLine.addDropdown((dropdown) => {
|
|
||||||
dropdown
|
|
||||||
.addOption("title", "Title")
|
|
||||||
.setValue("")
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.properties[propertyIndex].customType = value; // Update the customType of the specific property
|
|
||||||
});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
propertyLine
|
|
||||||
.setName("Property " + (propertyIndex))
|
|
||||||
|
|
||||||
propertyLine.addText((text) => {
|
|
||||||
text
|
|
||||||
.setPlaceholder("Property name")
|
|
||||||
.setValue("")
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.properties[propertyIndex].customName = value; // Update the customValue of the specific property
|
|
||||||
});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
propertyLine.addDropdown((dropdown) => {
|
|
||||||
dropdown
|
|
||||||
.addOption("text", "Text")
|
|
||||||
.addOption("number", "Number")
|
|
||||||
.addOption("select", "Select")
|
|
||||||
.addOption("multi_select", "Multi-Select")
|
|
||||||
.addOption("date", "Date")
|
|
||||||
// .addOption("person", "Person")
|
|
||||||
.addOption("file", "Files & Media")
|
|
||||||
.addOption("checkbox", "Checkbox")
|
|
||||||
.addOption("url", "URL")
|
|
||||||
.addOption("email", "Email")
|
|
||||||
.addOption("phone_number", "Phone Number")
|
|
||||||
// .addOption("formula", "Formula")
|
|
||||||
// .addOption("relation", "Relation")
|
|
||||||
// .addOption("rollup", "Rollup")
|
|
||||||
// .addOption("created_time", "Created time")
|
|
||||||
// .addOption("created_by", "Created by")
|
|
||||||
// .addOption("last_edited_time", "Last Edited Time")
|
|
||||||
// .addOption("last_edited_by", "Last Edited By")
|
|
||||||
.setValue("text")
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.properties[propertyIndex].customType = value; // Update the customType of the specific property
|
|
||||||
});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
propertyLine.addButton((button) => {
|
|
||||||
return button
|
|
||||||
.setTooltip("Delete")
|
|
||||||
.setIcon("trash")
|
|
||||||
.onClick(async () => {
|
|
||||||
// Handle the deletion of this property line
|
|
||||||
this.propertyLines = this.propertyLines.filter(line => line !== propertyLine);
|
|
||||||
this.properties.splice(propertyIndex, 1); // Remove the property from the array
|
|
||||||
propertyLine.settingEl.remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.propertyLines.push(propertyLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
display(): void {
|
|
||||||
|
|
||||||
this.containerEl.addClass("custom-modal");
|
|
||||||
this.titleEl.setText("Add Custom Property");
|
|
||||||
|
|
||||||
let {contentEl} = this;
|
|
||||||
contentEl.empty();
|
|
||||||
|
|
||||||
const customDiv = contentEl.createDiv("custom-div");
|
|
||||||
|
|
||||||
new Setting(customDiv)
|
|
||||||
.setName("Add new property")
|
|
||||||
.setDesc("Add new property match with your notion database")
|
|
||||||
.addButton((button) => {
|
|
||||||
return button
|
|
||||||
.setTooltip("Add")
|
|
||||||
.setIcon("plus")
|
|
||||||
.onClick(async () => {
|
|
||||||
const customTabs = customDiv.createDiv("custom-tabs");
|
|
||||||
this.createPropertyLine(customTabs);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
let footerEl = this.contentEl.createDiv("save-custom-value");
|
|
||||||
let saveButton = new Setting(footerEl)
|
|
||||||
saveButton.addButton((button) => {
|
|
||||||
return button
|
|
||||||
.setTooltip("Save")
|
|
||||||
.setIcon("checkmark")
|
|
||||||
.onClick(async () => {
|
|
||||||
this.close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
saveButton.addExtraButton((button) => {
|
|
||||||
return button
|
|
||||||
.setTooltip("Cancel")
|
|
||||||
.setIcon("cross")
|
|
||||||
.onClick(async () => {
|
|
||||||
this.close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
onOpen(): void {
|
|
||||||
this.display();
|
|
||||||
}
|
|
||||||
|
|
||||||
onClose(): void {
|
|
||||||
const {contentEl} = this;
|
|
||||||
|
|
||||||
contentEl.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import {App, ButtonComponent, Modal, Setting} from "obsidian";
|
import { App, ButtonComponent, Setting } from "obsidian";
|
||||||
import {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";
|
||||||
import {i18nConfig} from "../lang/I18n";
|
import { i18nConfig } from "../lang/I18n";
|
||||||
import {CustomModal} from "./CustomModal";
|
|
||||||
|
|
||||||
export class EditModal extends SettingModal {
|
export class EditModal extends SettingModal {
|
||||||
|
propertyLines: Setting[] = []; // Store all property line settings
|
||||||
|
[key: string]: any; // Index signature
|
||||||
dataTemp: Record<string, any> = {
|
dataTemp: Record<string, any> = {
|
||||||
databaseFormatTemp: '',
|
databaseFormatTemp: '',
|
||||||
// databaseFormatTempInd: false,
|
// databaseFormatTempInd: false,
|
||||||
@@ -70,7 +71,7 @@ export class EditModal extends SettingModal {
|
|||||||
this.dataTemp.tagButtonTemp = dbDetails.tagButton;
|
this.dataTemp.tagButtonTemp = dbDetails.tagButton;
|
||||||
this.dataTemp.customTitleButtonTemp = dbDetails.customTitleButton;
|
this.dataTemp.customTitleButtonTemp = dbDetails.customTitleButton;
|
||||||
this.dataTemp.customTitleNameTemp = dbDetails.customTitleName;
|
this.dataTemp.customTitleNameTemp = dbDetails.customTitleName;
|
||||||
this.dataTemp.customPropertiesTemp = dbDetails.customProperties;
|
this.dataTemp.customPropertiesTemp = dbDetails.customProperties.map(prop => ({ ...prop })); // Ensure deep copy
|
||||||
// this.dataTemp.customValues = dbDetails.customValues;
|
// this.dataTemp.customValues = dbDetails.customValues;
|
||||||
this.dataTemp.savedTemp = dbDetails.saved;
|
this.dataTemp.savedTemp = dbDetails.saved;
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ export class EditModal extends SettingModal {
|
|||||||
this.dataPrev.tagButtonPrev = dbDetails.tagButton;
|
this.dataPrev.tagButtonPrev = dbDetails.tagButton;
|
||||||
this.dataPrev.customTitleButtonPrev = dbDetails.customTitleButton;
|
this.dataPrev.customTitleButtonPrev = dbDetails.customTitleButton;
|
||||||
this.dataPrev.customTitleNamePrev = dbDetails.customTitleName;
|
this.dataPrev.customTitleNamePrev = dbDetails.customTitleName;
|
||||||
this.dataPrev.customPropertiesPrev = dbDetails.customProperties;
|
this.dataPrev.customPropertiesPrev = dbDetails.customProperties.map(prop => ({ ...prop })); // Ensure deep copy
|
||||||
// this.dataTemp.customValues = dbDetails.customValues;
|
// this.dataTemp.customValues = dbDetails.customValues;
|
||||||
this.dataPrev.savedPrev = dbDetails.saved;
|
this.dataPrev.savedPrev = dbDetails.saved;
|
||||||
}
|
}
|
||||||
@@ -94,65 +95,67 @@ export class EditModal extends SettingModal {
|
|||||||
this.containerEl.addClass("edit-modal");
|
this.containerEl.addClass("edit-modal");
|
||||||
this.titleEl.setText('Edit Database');
|
this.titleEl.setText('Edit Database');
|
||||||
|
|
||||||
let {contentEl} = this;
|
let { contentEl } = this;
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
|
|
||||||
const editDiv = contentEl.createDiv('edit-div');
|
const editDiv = contentEl.createDiv('edit-div');
|
||||||
const nextTabs = contentEl.createDiv('next-tabs');
|
const nextTabs = contentEl.createDiv('next-tabs');
|
||||||
|
|
||||||
new Setting(editDiv)
|
|
||||||
.setName(i18nConfig.databaseFormat)
|
|
||||||
.setDesc(i18nConfig.databaseFormatDesc)
|
|
||||||
.addDropdown((component) => {
|
|
||||||
component
|
|
||||||
.addOption('none', '')
|
|
||||||
.addOption('general', i18nConfig.databaseGeneral)
|
|
||||||
.addOption('next', i18nConfig.databaseNext)
|
|
||||||
.addOption('custom', i18nConfig.databaseCustom)
|
|
||||||
.setValue(this.dataTemp.databaseFormatTemp)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.dataTemp.databaseFormatTemp = value;
|
|
||||||
nextTabs.empty();
|
|
||||||
this.updateContentBasedOnSelection(value, nextTabs);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Initialize content based on the current dropdown value
|
new Setting(editDiv)
|
||||||
this.updateContentBasedOnSelection(this.dataTemp.databaseFormatTemp, nextTabs);
|
.setName(i18nConfig.databaseFormat)
|
||||||
});
|
.setDesc(i18nConfig.databaseFormatDesc)
|
||||||
|
.addDropdown((component) => {
|
||||||
|
component
|
||||||
|
.addOption('none', '')
|
||||||
|
.addOption('general', i18nConfig.databaseGeneral)
|
||||||
|
.addOption('next', i18nConfig.databaseNext)
|
||||||
|
.addOption('custom', i18nConfig.databaseCustom)
|
||||||
|
.setValue(this.dataTemp.databaseFormatTemp)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.dataTemp.databaseFormatTemp = value;
|
||||||
|
nextTabs.empty();
|
||||||
|
this.updateContentBasedOnSelection(value, nextTabs);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize content based on the current dropdown value
|
||||||
|
this.updateContentBasedOnSelection(this.dataTemp.databaseFormatTemp, nextTabs);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// add save button
|
// add save button
|
||||||
let footerEl = contentEl.createDiv('save-button');
|
let footerEl = contentEl.createDiv('save-button');
|
||||||
let saveButton = new Setting(footerEl)
|
let saveButton = new Setting(footerEl)
|
||||||
saveButton.addButton((button: ButtonComponent) => {
|
saveButton.addButton((button: ButtonComponent) => {
|
||||||
return button
|
return button
|
||||||
.setTooltip('Save')
|
.setTooltip('Save')
|
||||||
.setIcon('checkmark')
|
.setIcon('checkmark')
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
this.dataTemp.savedTempInd = true;
|
this.dataTemp.savedTempInd = true;
|
||||||
this.dataTemp.savedTemp = true;
|
this.dataTemp.savedTemp = true;
|
||||||
this.close();
|
// console.log(this.dataTemp);
|
||||||
});
|
// console.log(this.dataPrev);
|
||||||
}
|
this.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
saveButton.addExtraButton((button) => {
|
saveButton.addExtraButton((button) => {
|
||||||
return button
|
return button
|
||||||
.setTooltip('Cancel')
|
.setTooltip('Cancel')
|
||||||
.setIcon('cross')
|
.setIcon('cross')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
this.dataTemp.savedTempInd = false;
|
// console.log(this.dataTemp);
|
||||||
this.close();
|
// console.log(this.dataPrev);
|
||||||
});
|
this.close();
|
||||||
}
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onOpen(): void {
|
onOpen(): void {
|
||||||
this.display()
|
this.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updateContentBasedOnSelection(value: string, nextTabs: HTMLElement): void {
|
updateContentBasedOnSelection(value: string, nextTabs: HTMLElement): void {
|
||||||
// Clear existing content
|
// Clear existing content
|
||||||
nextTabs.empty();
|
nextTabs.empty();
|
||||||
@@ -162,13 +165,13 @@ export class EditModal extends SettingModal {
|
|||||||
nextTabs.createEl('h3', { text: i18nConfig.NotionGeneralSettingHeader });
|
nextTabs.createEl('h3', { text: i18nConfig.NotionGeneralSettingHeader });
|
||||||
|
|
||||||
// add full name
|
// add full name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.dataTemp.databaseFullNameTemp,'dataTemp', 'databaseFullNameTemp')
|
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.dataTemp.databaseFullNameTemp, 'dataTemp', 'databaseFullNameTemp')
|
||||||
|
|
||||||
// add abbreviate name
|
// add abbreviate name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.dataTemp.databaseAbbreviateNameTemp, 'dataTemp','databaseAbbreviateNameTemp')
|
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.dataTemp.databaseAbbreviateNameTemp, 'dataTemp', 'databaseAbbreviateNameTemp')
|
||||||
|
|
||||||
// tag button
|
// tag button
|
||||||
this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.dataTemp.tagButtonTemp, 'dataTemp','tagButtonTemp')
|
this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.dataTemp.tagButtonTemp, 'dataTemp', 'tagButtonTemp')
|
||||||
|
|
||||||
// add custom title button
|
// add custom title button
|
||||||
|
|
||||||
@@ -180,49 +183,28 @@ export class EditModal extends SettingModal {
|
|||||||
.setValue(this.dataTemp.customTitleButtonTemp)
|
.setValue(this.dataTemp.customTitleButtonTemp)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.dataTemp.customTitleButtonTemp = value;
|
this.dataTemp.customTitleButtonTemp = value;
|
||||||
|
|
||||||
this.updateSettingEl(CustomNameEl, value)
|
this.updateSettingEl(CustomNameEl, value)
|
||||||
|
|
||||||
// this.updateSettingEl(CustomValuesEl, value)
|
|
||||||
|
|
||||||
// await this.plugin.saveSettings();
|
|
||||||
// await this.plugin.commands.updateCommand();
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// add custom title name
|
// add custom title name
|
||||||
const CustomNameEl = this.createStyleDiv('custom-name', (this.dataTemp.customTitleButtonTemp), nextTabs);
|
const CustomNameEl = this.createStyleDiv('custom-name', (this.dataTemp.customTitleButtonTemp), nextTabs);
|
||||||
this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.dataTemp.customTitleNameTemp,'dataTemp', 'customTitleNameTemp')
|
this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.dataTemp.customTitleNameTemp, 'dataTemp', 'customTitleNameTemp')
|
||||||
|
|
||||||
|
|
||||||
// add api key
|
// add api key
|
||||||
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.dataTemp.notionAPITemp, 'dataTemp','notionAPITemp')
|
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.dataTemp.notionAPITemp, 'dataTemp', 'notionAPITemp')
|
||||||
|
|
||||||
// add database id
|
// add database id
|
||||||
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.dataTemp.databaseIDTemp, 'dataTemp','databaseIDTemp')
|
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.DatabaseIDDesc, 'password', i18nConfig.DatabaseIDText, this.dataTemp.databaseIDTemp, 'dataTemp', 'databaseIDTemp')
|
||||||
|
|
||||||
|
|
||||||
} else if (value === 'next') {
|
} else if (value === 'next') {
|
||||||
|
|
||||||
nextTabs.createEl('h3', { text: i18nConfig.NotionNextSettingHeader });
|
nextTabs.createEl('h3', { text: i18nConfig.NotionNextSettingHeader });
|
||||||
|
|
||||||
// add full name
|
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.dataTemp.databaseFullNameTemp, 'dataTemp','databaseFullNameTemp')
|
|
||||||
|
|
||||||
// add abbreviate name
|
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.dataTemp.databaseAbbreviateNameTemp, 'dataTemp','databaseAbbreviateNameTemp')
|
|
||||||
|
|
||||||
// add api key
|
|
||||||
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.dataTemp.notionAPITemp, 'dataTemp','notionAPITemp')
|
|
||||||
|
|
||||||
// add database id
|
|
||||||
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.dataTemp.databaseIDTemp, 'dataTemp','databaseIDTemp')
|
|
||||||
|
|
||||||
} else if (value === 'custom') {
|
|
||||||
|
|
||||||
nextTabs.createEl('h3', {text: i18nConfig.NotionCustomSettingHeader});
|
|
||||||
|
|
||||||
// add full name
|
// add full name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.dataTemp.databaseFullNameTemp, 'dataTemp', 'databaseFullNameTemp')
|
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.dataTemp.databaseFullNameTemp, 'dataTemp', 'databaseFullNameTemp')
|
||||||
|
|
||||||
@@ -233,33 +215,125 @@ export class EditModal extends SettingModal {
|
|||||||
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.dataTemp.notionAPITemp, 'dataTemp', 'notionAPITemp')
|
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.dataTemp.notionAPITemp, 'dataTemp', 'notionAPITemp')
|
||||||
|
|
||||||
// add database id
|
// add database id
|
||||||
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.dataTemp.databaseIDTemp, 'dataTemp', 'databaseIDTemp')
|
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.DatabaseIDDesc, 'password', i18nConfig.DatabaseIDText, this.dataTemp.databaseIDTemp, 'dataTemp', 'databaseIDTemp')
|
||||||
|
|
||||||
// add new property button
|
} else if (value === 'custom') {
|
||||||
new Setting(nextTabs)
|
|
||||||
.setName(i18nConfig.NotionCustomValues)
|
|
||||||
.setDesc(i18nConfig.NotionCustomValuesDesc)
|
|
||||||
.addButton((button: ButtonComponent) => {
|
|
||||||
return button
|
|
||||||
.setTooltip('Add new property')
|
|
||||||
.setIcon('plus')
|
|
||||||
.onClick(async () => {
|
|
||||||
let customModal = new CustomModal(this.app);
|
|
||||||
|
|
||||||
customModal.onClose = () => {
|
nextTabs.createEl('h3', { text: i18nConfig.NotionCustomSettingHeader });
|
||||||
|
|
||||||
this.renderCustomPreview(customModal.properties, nextTabs)
|
// add full name
|
||||||
this.dataTemp.customPropertiesTemp = customModal.properties;
|
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.dataTemp.databaseFullNameTemp, 'dataTemp', 'databaseFullNameTemp')
|
||||||
}
|
|
||||||
|
|
||||||
customModal.open();
|
// add abbreviate name
|
||||||
});
|
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.dataTemp.databaseAbbreviateNameTemp, 'dataTemp', 'databaseAbbreviateNameTemp')
|
||||||
}
|
|
||||||
);
|
// add api key
|
||||||
|
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.dataTemp.notionAPITemp, 'dataTemp', 'notionAPITemp')
|
||||||
|
|
||||||
|
// add database id
|
||||||
|
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.DatabaseIDDesc, 'password', i18nConfig.DatabaseIDText, this.dataTemp.databaseIDTemp, 'dataTemp', 'databaseIDTemp')
|
||||||
|
|
||||||
|
// add custom properties
|
||||||
|
this.initializePropertyLines(nextTabs, this.dataTemp.customPropertiesTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initializePropertyLines(containerEl: HTMLElement, properties: customProperty[]): void {
|
||||||
|
if (!containerEl) {
|
||||||
|
console.error('Failed to initialize property lines: containerEl is null');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName("Add New Property")
|
||||||
|
.setDesc("Click to add a new property")
|
||||||
|
.addButton(button => {
|
||||||
|
return button
|
||||||
|
.setButtonText('Add')
|
||||||
|
.setTooltip('Add one more property')
|
||||||
|
.onClick(() => {
|
||||||
|
this.createPropertyLine(containerEl, properties);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
properties.forEach(property => {
|
||||||
|
this.updatePropertyLine(containerEl, property, properties);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
updatePropertyLine(containerEl: HTMLElement, property: customProperty, properties: customProperty[]) {
|
||||||
|
let isExistingProperty = property !== null;
|
||||||
|
const propertyIndex = isExistingProperty ? property.index : properties.length;
|
||||||
|
|
||||||
|
const propertyLine = new Setting(containerEl)
|
||||||
|
.setName(propertyIndex === 0 ? i18nConfig.CustomPropertyFirstColumn : `${i18nConfig.CustomProperty} ${propertyIndex}`)
|
||||||
|
.setDesc(propertyIndex === 0 ? i18nConfig.CustomPropertyFirstColumnDesc : "");
|
||||||
|
|
||||||
|
propertyLine.addText(text => {
|
||||||
|
text.setPlaceholder(i18nConfig.CustomPropertyName)
|
||||||
|
.setValue(isExistingProperty ? property.customName : "")
|
||||||
|
.onChange(value => {
|
||||||
|
const actualIndex = properties.findIndex(p => p.index === propertyIndex);
|
||||||
|
if (actualIndex !== -1) {
|
||||||
|
properties[actualIndex].customName = value;
|
||||||
|
} else {
|
||||||
|
properties.push({ customName: value, customType: '', index: propertyIndex });
|
||||||
|
isExistingProperty = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
propertyLine.addDropdown((dropdown) => {
|
||||||
|
const options: Record<string, string> = {
|
||||||
|
'rich_text': 'Text',
|
||||||
|
'number': 'Number',
|
||||||
|
'select': 'Select',
|
||||||
|
'multi_select': 'Multi-Select',
|
||||||
|
'date': 'Date',
|
||||||
|
'files': 'Files & Media',
|
||||||
|
'checkbox': 'Checkbox',
|
||||||
|
'url': 'URL',
|
||||||
|
'email': 'Email',
|
||||||
|
'phone_number': 'Phone Number'
|
||||||
|
};
|
||||||
|
|
||||||
|
if (propertyIndex === 0) {
|
||||||
|
dropdown.addOption('title', 'Title');
|
||||||
|
} else {
|
||||||
|
Object.keys(options).forEach(key => {
|
||||||
|
dropdown.addOption(key, options[key]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
dropdown.setValue(isExistingProperty ? property.customType : "")
|
||||||
|
.onChange(value => {
|
||||||
|
const actualIndex = properties.findIndex(p => p.index === propertyIndex);
|
||||||
|
if (actualIndex !== -1) {
|
||||||
|
properties[actualIndex].customType = value;
|
||||||
|
} else if (!isExistingProperty) {
|
||||||
|
properties.push({ customName: '', customType: value, index: propertyIndex });
|
||||||
|
isExistingProperty = true; // Update the flag to prevent re-adding
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (propertyIndex > 0) {
|
||||||
|
propertyLine.addButton(button => {
|
||||||
|
return button
|
||||||
|
.setTooltip("Delete")
|
||||||
|
.setIcon("trash")
|
||||||
|
.onClick(() => {
|
||||||
|
console.log('Deleting property', properties[propertyIndex]);
|
||||||
|
this.deleteProperty(propertyIndex, properties);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.propertyLines.push(propertyLine);
|
||||||
|
this.updatePropertyLines();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
createStyleDiv(className: string, commandValue: boolean = false, parentEl: HTMLElement): HTMLDivElement {
|
createStyleDiv(className: string, commandValue: boolean = false, parentEl: HTMLElement): HTMLDivElement {
|
||||||
return super.createStyleDiv(className, commandValue, parentEl);
|
return super.createStyleDiv(className, commandValue, parentEl);
|
||||||
|
|||||||
@@ -1,13 +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 { 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;
|
||||||
@@ -24,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
|
||||||
@@ -120,12 +122,9 @@ export class PreviewModal extends Modal {
|
|||||||
|
|
||||||
if (this.dbDetails.format === 'custom') {
|
if (this.dbDetails.format === 'custom') {
|
||||||
|
|
||||||
const customPropertiesEl = new Setting(previewEl)
|
const customPrv = previewEl.createDiv("custom-tabs");
|
||||||
customPropertiesEl
|
|
||||||
.setName('Custom Properties')
|
this.previewPropertyLine(previewEl, this.dbDetails.customProperties);
|
||||||
.addTextArea(text => text
|
|
||||||
.setValue(JSON.stringify(this.dbDetails.customProperties, null, 2))
|
|
||||||
.setDisabled(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -136,4 +135,44 @@ export class PreviewModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
previewPropertyLine(containerEl: HTMLElement, properties: customProperty[]): void {
|
||||||
|
|
||||||
|
properties.forEach((property, index) => {
|
||||||
|
const propertyLine = new Setting(containerEl)
|
||||||
|
.setName(index === 0 ? i18nConfig.CustomPropertyFirstColumn : `${i18nConfig.CustomProperty} ${index}`)
|
||||||
|
.setDesc(index === 0 ? i18nConfig.CustomPropertyFirstColumnDesc : "");
|
||||||
|
|
||||||
|
propertyLine.addText(text => {
|
||||||
|
text.setPlaceholder(i18nConfig.CustomPropertyName)
|
||||||
|
.setValue(property.customName)
|
||||||
|
.setDisabled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
propertyLine.addDropdown((dropdown) => {
|
||||||
|
const options: Record<string, string> = {
|
||||||
|
'title': 'Title',
|
||||||
|
'rich_text': 'Text',
|
||||||
|
'number': 'Number',
|
||||||
|
'select': 'Select',
|
||||||
|
'multi_select': 'Multi-Select',
|
||||||
|
'date': 'Date',
|
||||||
|
'files': 'Files & Media',
|
||||||
|
'checkbox': 'Checkbox',
|
||||||
|
'url': 'URL',
|
||||||
|
'email': 'Email',
|
||||||
|
'phone_number': 'Phone Number',
|
||||||
|
// Additional options can be added here
|
||||||
|
};
|
||||||
|
|
||||||
|
// Populate dropdown with options
|
||||||
|
Object.keys(options).forEach(key => {
|
||||||
|
dropdown.addOption(key, options[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
dropdown.setValue(property.customType)
|
||||||
|
.setDisabled(true); // Disable dropdown to prevent changes
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
import {
|
import {
|
||||||
Modal,
|
Modal,
|
||||||
Setting,
|
Setting,
|
||||||
PluginSettingTab,
|
|
||||||
ButtonComponent, App
|
ButtonComponent, App
|
||||||
} from 'obsidian';
|
} from 'obsidian';
|
||||||
|
|
||||||
import {i18nConfig} from "../lang/I18n";
|
import { i18nConfig } from "../lang/I18n";
|
||||||
import ObsidianSyncNotionPlugin from "../main";
|
import ObsidianSyncNotionPlugin from "../main";
|
||||||
import {DatabaseDetails, ObsidianSettingTab} from "./settingTabs";
|
import { DatabaseDetails, ObsidianSettingTab } from "./settingTabs";
|
||||||
import {CustomModal} from "./CustomModal";
|
|
||||||
|
|
||||||
|
export interface customProperty {
|
||||||
|
customName: string;
|
||||||
|
customType: string;
|
||||||
|
index: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class SettingModal extends Modal {
|
export class SettingModal extends Modal {
|
||||||
|
propertyLines: Setting[] = []; // Store all property line settings
|
||||||
|
properties: customProperty[] = []; // Array to store property values and types
|
||||||
[key: string]: any; // Index signature
|
[key: string]: any; // Index signature
|
||||||
data: Record<string, any> = {
|
data: Record<string, any> = {
|
||||||
databaseFormat: 'none',
|
databaseFormat: 'none',
|
||||||
@@ -47,7 +52,6 @@ export class SettingModal extends Modal {
|
|||||||
// this.data.customValues = dbDetails.customValues;
|
// this.data.customValues = dbDetails.customValues;
|
||||||
this.data.saved = dbDetails.saved;
|
this.data.saved = dbDetails.saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
display(): void {
|
display(): void {
|
||||||
@@ -55,79 +59,59 @@ export class SettingModal extends Modal {
|
|||||||
this.titleEl.setText('Add new database');
|
this.titleEl.setText('Add new database');
|
||||||
|
|
||||||
// create the dropdown button to select the database format
|
// create the dropdown button to select the database format
|
||||||
let {contentEl} = this;
|
let { contentEl } = this;
|
||||||
contentEl.empty();
|
contentEl.empty();
|
||||||
|
|
||||||
const settingDiv = contentEl.createDiv('setting-div');
|
const settingDiv = contentEl.createDiv('setting-div');
|
||||||
const nextTabs = contentEl.createDiv('next-tabs');
|
const nextTabs = contentEl.createDiv('next-tabs');
|
||||||
|
|
||||||
|
|
||||||
if (this.data.saved) {
|
new Setting(settingDiv)
|
||||||
new Setting(settingDiv)
|
.setName(i18nConfig.databaseFormat)
|
||||||
.setName(i18nConfig.databaseFormat)
|
.setDesc(i18nConfig.databaseFormatDesc)
|
||||||
.setDesc(i18nConfig.databaseFormatDesc)
|
.addDropdown((component) => {
|
||||||
.addDropdown((component) => {
|
component
|
||||||
component
|
.addOption('none', '')
|
||||||
.addOption('none', '')
|
.addOption('general', i18nConfig.databaseGeneral)
|
||||||
.addOption('general', i18nConfig.databaseGeneral)
|
.addOption('next', i18nConfig.databaseNext)
|
||||||
.addOption('next', i18nConfig.databaseNext)
|
.addOption('custom', i18nConfig.databaseCustom)
|
||||||
.addOption('custom', i18nConfig.databaseCustom)
|
.setValue(this.data.databaseFormat)
|
||||||
.setValue(this.data.databaseFormat)
|
.onChange(async (value) => {
|
||||||
.onChange(async (value) => {
|
this.data.databaseFormat = value;
|
||||||
this.data.databaseFormat = value;
|
nextTabs.empty();
|
||||||
nextTabs.empty();
|
this.updateContentBasedOnSelection(value, nextTabs);
|
||||||
this.updateContentBasedOnSelection(value, nextTabs);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Initialize content based on the current dropdown value
|
// Initialize content based on the current dropdown value
|
||||||
this.updateContentBasedOnSelection(this.data.databaseFormat, nextTabs);
|
(this.data.saved) ? this.updateContentBasedOnSelection(this.data.databaseFormat, nextTabs) : this.updateContentBasedOnSelection(this.plugin.settings.databaseFormat, nextTabs);
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
});
|
||||||
new Setting(settingDiv)
|
|
||||||
.setName(i18nConfig.databaseFormat)
|
|
||||||
.setDesc(i18nConfig.databaseFormatDesc)
|
|
||||||
.addDropdown((component) => {
|
|
||||||
component
|
|
||||||
.addOption('none', '')
|
|
||||||
.addOption('general', i18nConfig.databaseGeneral)
|
|
||||||
.addOption('next', i18nConfig.databaseNext)
|
|
||||||
.addOption('custom', i18nConfig.databaseCustom)
|
|
||||||
.setValue(this.data.databaseFormat)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.data.databaseFormat = value;
|
|
||||||
nextTabs.empty();
|
|
||||||
this.updateContentBasedOnSelection(value, nextTabs);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Initialize content based on the current dropdown value
|
|
||||||
this.updateContentBasedOnSelection(this.plugin.settings.databaseFormat, nextTabs);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// add save button
|
// add save button
|
||||||
let footerEl = contentEl.createDiv('save-button');
|
let footerEl = contentEl.createDiv('save-button');
|
||||||
let saveButton = new Setting(footerEl)
|
let saveButton = new Setting(footerEl)
|
||||||
saveButton.addButton((button: ButtonComponent) => {
|
saveButton.addButton((button: ButtonComponent) => {
|
||||||
return button
|
return button
|
||||||
.setTooltip('Save')
|
.setTooltip('Save')
|
||||||
.setIcon('checkmark')
|
.setIcon('checkmark')
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
this.data.saved = true;
|
this.data.saved = true;
|
||||||
this.close();
|
this.data.customProperties = this.properties;
|
||||||
});
|
this.close();
|
||||||
}
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
saveButton.addExtraButton((button) => {
|
saveButton.addExtraButton((button) => {
|
||||||
return button
|
return button
|
||||||
.setTooltip('Cancel')
|
.setTooltip('Cancel')
|
||||||
.setIcon('cross')
|
.setIcon('cross')
|
||||||
.onClick(() => {
|
.onClick(() => {
|
||||||
this.data.saved = false;
|
this.data.saved = false;
|
||||||
this.close();
|
// this.data.customProperties = this.properties;
|
||||||
});
|
this.close();
|
||||||
}
|
});
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +121,7 @@ export class SettingModal extends Modal {
|
|||||||
|
|
||||||
// Generate content based on the selected value
|
// Generate content based on the selected value
|
||||||
if (value === 'general') {
|
if (value === 'general') {
|
||||||
nextTabs.createEl('h3', {text: i18nConfig.NotionGeneralSettingHeader});
|
nextTabs.createEl('h3', { text: i18nConfig.NotionGeneralSettingHeader });
|
||||||
|
|
||||||
// add full name
|
// add full name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.data.databaseFullName, 'data', 'databaseFullName')
|
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.data.databaseFullName, 'data', 'databaseFullName')
|
||||||
@@ -158,13 +142,8 @@ export class SettingModal extends Modal {
|
|||||||
.setValue(this.data.customTitleButton)
|
.setValue(this.data.customTitleButton)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.data.customTitleButton = value;
|
this.data.customTitleButton = value;
|
||||||
|
|
||||||
this.updateSettingEl(CustomNameEl, value)
|
this.updateSettingEl(CustomNameEl, value)
|
||||||
|
|
||||||
// this.updateSettingEl(CustomValuesEl, value)
|
|
||||||
|
|
||||||
// await this.plugin.saveSettings();
|
|
||||||
// await this.plugin.commands.updateCommand();
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -178,12 +157,12 @@ export class SettingModal extends Modal {
|
|||||||
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'data', 'notionAPI')
|
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'data', 'notionAPI')
|
||||||
|
|
||||||
// add database id
|
// add database id
|
||||||
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'data', 'databaseID')
|
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.DatabaseIDDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'data', 'databaseID')
|
||||||
|
|
||||||
|
|
||||||
} else if (value === 'next') {
|
} else if (value === 'next') {
|
||||||
|
|
||||||
nextTabs.createEl('h3', {text: i18nConfig.NotionNextSettingHeader});
|
nextTabs.createEl('h3', { text: i18nConfig.NotionNextSettingHeader });
|
||||||
|
|
||||||
// add full name
|
// add full name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.data.databaseFullName, 'data', 'databaseFullName')
|
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.data.databaseFullName, 'data', 'databaseFullName')
|
||||||
@@ -196,11 +175,11 @@ export class SettingModal extends Modal {
|
|||||||
|
|
||||||
|
|
||||||
// add database id
|
// add database id
|
||||||
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'data', 'databaseID')
|
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.DatabaseIDDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'data', 'databaseID')
|
||||||
|
|
||||||
} else if (value === 'custom') {
|
} else if (value === 'custom') {
|
||||||
|
|
||||||
nextTabs.createEl('h3', {text: i18nConfig.NotionCustomSettingHeader});
|
nextTabs.createEl('h3', { text: i18nConfig.NotionCustomSettingHeader });
|
||||||
|
|
||||||
// add full name
|
// add full name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.data.databaseFullName, 'data', 'databaseFullName')
|
this.createSettingEl(nextTabs, i18nConfig.databaseFullName, i18nConfig.databaseFullNameDesc, 'text', i18nConfig.databaseFullNameText, this.data.databaseFullName, 'data', 'databaseFullName')
|
||||||
@@ -212,31 +191,23 @@ export class SettingModal extends Modal {
|
|||||||
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'data', 'notionAPI')
|
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'data', 'notionAPI')
|
||||||
|
|
||||||
// add database id
|
// add database id
|
||||||
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'data', 'databaseID')
|
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.DatabaseIDDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'data', 'databaseID')
|
||||||
|
|
||||||
// add new property button
|
// add new property button
|
||||||
new Setting(nextTabs)
|
new Setting(nextTabs)
|
||||||
.setName(i18nConfig.NotionCustomValues)
|
.setName(i18nConfig.NotionCustomValues)
|
||||||
.setDesc(i18nConfig.NotionCustomValuesDesc)
|
.setDesc(i18nConfig.NotionCustomValuesDesc)
|
||||||
.addButton((button: ButtonComponent) => {
|
.addButton((button: ButtonComponent) => {
|
||||||
return button
|
return button
|
||||||
.setTooltip('Add new property')
|
.setTooltip('Add one more property')
|
||||||
.setIcon('plus')
|
.setButtonText('Add New Property')
|
||||||
.onClick(async () => {
|
.onClick(async () => {
|
||||||
let customModal = new CustomModal(this.app);
|
const customTabs = nextTabs.createDiv("custom-tabs");
|
||||||
|
this.createPropertyLine(customTabs, this.properties);
|
||||||
customModal.onClose = () => {
|
});
|
||||||
|
}
|
||||||
this.renderCustomPreview(customModal.properties, nextTabs)
|
|
||||||
this.data.customProperties = customModal.properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
customModal.open();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -245,16 +216,108 @@ export class SettingModal extends Modal {
|
|||||||
this.display()
|
this.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCustomPreview(properties: any[], nextTabs: HTMLElement) {
|
createPropertyLine(containerEl: HTMLElement, properties: customProperty[]): void {
|
||||||
const previewContainer = nextTabs.createDiv('preview-container');
|
const propertyIndex = properties.length;
|
||||||
|
|
||||||
properties.forEach((property: { customName: any; customType: any; }) => {
|
properties.push({ customName: "", customType: "", index: propertyIndex });
|
||||||
const propertyEl = previewContainer.createEl('div', {cls: 'property-preview'});
|
|
||||||
propertyEl.createEl('span', {text: `Property: ${property.customName}, Type: ${property.customType}`});
|
const propertyLine = new Setting(containerEl)
|
||||||
|
.setName(propertyIndex === 0 ? i18nConfig.CustomPropertyFirstColumn : `${i18nConfig.CustomProperty} ${propertyIndex}`)
|
||||||
|
.setDesc(propertyIndex === 0 ? i18nConfig.CustomPropertyFirstColumnDesc : "");
|
||||||
|
|
||||||
|
propertyLine.addText(text => {
|
||||||
|
text.setPlaceholder(i18nConfig.CustomPropertyName)
|
||||||
|
.setValue("")
|
||||||
|
.onChange(value => {
|
||||||
|
let actualIndex = properties.findIndex(p => p.index === propertyIndex);
|
||||||
|
if (actualIndex !== -1) {
|
||||||
|
properties[actualIndex].customName = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
propertyLine.addDropdown((dropdown) => {
|
||||||
|
const options: Record<string, string> = {
|
||||||
|
'rich_text': 'Text',
|
||||||
|
'number': 'Number',
|
||||||
|
'select': 'Select',
|
||||||
|
'multi_select': 'Multi-Select',
|
||||||
|
'date': 'Date',
|
||||||
|
'files': 'Files & Media',
|
||||||
|
'checkbox': 'Checkbox',
|
||||||
|
'url': 'URL',
|
||||||
|
'email': 'Email',
|
||||||
|
'phone_number': 'Phone Number',
|
||||||
|
// 'formula': 'Formula',
|
||||||
|
// 'relation': 'Relation',
|
||||||
|
// 'rollup': 'Rollup',
|
||||||
|
// 'created_time': 'Created time',
|
||||||
|
// 'created_by': 'Created by',
|
||||||
|
// 'last_edited_time': 'Last Edited Time',
|
||||||
|
// 'last_edited_by': 'Last Edited By',
|
||||||
|
};
|
||||||
|
|
||||||
|
const currentProperty = properties[propertyIndex];
|
||||||
|
|
||||||
|
if (propertyIndex === 0) {
|
||||||
|
dropdown.addOption("title", "Title");
|
||||||
|
} else {
|
||||||
|
Object.keys(options).forEach(key => {
|
||||||
|
dropdown.addOption(key, options[key]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dropdown.setValue("")
|
||||||
|
.onChange(value => {
|
||||||
|
if (currentProperty) {
|
||||||
|
currentProperty.customType = value;
|
||||||
|
// Retrieve the index of currentProperty from the properties array
|
||||||
|
const updatedIndex = properties.findIndex(p => p === currentProperty);
|
||||||
|
console.log(`Updated value at index ${updatedIndex}: ${value}`);
|
||||||
|
} else {
|
||||||
|
console.log("Property not found, may have been deleted.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if (propertyIndex > 0) {
|
||||||
|
propertyLine.addButton(button => {
|
||||||
|
return button
|
||||||
|
.setTooltip("Delete")
|
||||||
|
.setIcon("trash")
|
||||||
|
.onClick(() => {
|
||||||
|
this.deleteProperty(propertyIndex, properties);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.propertyLines.push(propertyLine);
|
||||||
|
this.updatePropertyLines(); // Ensure property lines are updated after creation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteProperty(propertyIndex: number, properties: customProperty[]): void {
|
||||||
|
let actualIndex = properties.findIndex(p => p.index === propertyIndex);
|
||||||
|
if (actualIndex !== -1) {
|
||||||
|
properties.splice(actualIndex, 1);
|
||||||
|
if (this.propertyLines[actualIndex]) {
|
||||||
|
this.propertyLines[actualIndex].settingEl.remove();
|
||||||
|
this.propertyLines.splice(actualIndex, 1);
|
||||||
|
}
|
||||||
|
// Update indices in the properties array
|
||||||
|
properties.forEach((prop, idx) => {
|
||||||
|
prop.index = idx;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.updatePropertyLines();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePropertyLines() {
|
||||||
|
this.propertyLines.forEach((line, idx) => {
|
||||||
|
line.setName(idx === 0 ? i18nConfig.CustomPropertyFirstColumn : `${i18nConfig.CustomProperty} ${idx}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 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, parentEl: HTMLElement) {
|
public createStyleDiv(className: string, commandValue: boolean = false, parentEl: HTMLElement) {
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
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;
|
||||||
proxy: string;
|
NotionLinkDisplay: boolean;
|
||||||
GeneralButton: boolean;
|
proxy: string;
|
||||||
tagButton: boolean;
|
GeneralButton: boolean;
|
||||||
customTitleButton: boolean;
|
tagButton: boolean;
|
||||||
customTitleName: string;
|
customTitleButton: boolean;
|
||||||
notionAPIGeneral: string;
|
customTitleName: string;
|
||||||
databaseIDGeneral: string;
|
notionAPIGeneral: string;
|
||||||
CustomButton: boolean;
|
databaseIDGeneral: string;
|
||||||
CustomValues: string;
|
CustomButton: boolean;
|
||||||
notionAPICustom: string;
|
CustomValues: string;
|
||||||
databaseIDCustom: string;
|
notionAPICustom: string;
|
||||||
[key: string]: any;
|
databaseIDCustom: string;
|
||||||
|
[key: string]: any;
|
||||||
databaseDetails: Record<string, DatabaseDetails>
|
databaseDetails: Record<string, DatabaseDetails>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,56 +37,58 @@ export interface DatabaseDetails {
|
|||||||
tagButton: boolean;
|
tagButton: boolean;
|
||||||
customTitleButton: boolean;
|
customTitleButton: boolean;
|
||||||
customTitleName: string;
|
customTitleName: string;
|
||||||
customProperties:{ customName: string, customType: string }[];
|
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: "",
|
||||||
proxy: "",
|
NotionLinkDisplay: true,
|
||||||
GeneralButton: true,
|
proxy: "",
|
||||||
tagButton: true,
|
GeneralButton: true,
|
||||||
customTitleButton: false,
|
tagButton: true,
|
||||||
customTitleName: "",
|
customTitleButton: false,
|
||||||
notionAPIGeneral: "",
|
customTitleName: "",
|
||||||
databaseIDGeneral: "",
|
notionAPIGeneral: "",
|
||||||
CustomButton: false,
|
databaseIDGeneral: "",
|
||||||
CustomValues: "",
|
CustomButton: false,
|
||||||
notionAPICustom: "",
|
CustomValues: "",
|
||||||
databaseIDCustom: "",
|
notionAPICustom: "",
|
||||||
|
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")
|
||||||
@@ -126,105 +128,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
|
||||||
|
// public createStyleDiv(className: string, commandValue: boolean = false) {
|
||||||
|
// return this.containerEl.createDiv(className, (div) => {
|
||||||
|
// 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.
|
||||||
// // notion next database settings
|
public createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any, settingsKey: string) {
|
||||||
//
|
if (type === 'password') {
|
||||||
// const NextTabs = new SettingNextTabs(this.app, this.plugin, this);
|
return new Setting(containerEl)
|
||||||
//
|
.setName(name)
|
||||||
// NextTabs.display();
|
.setDesc(desc)
|
||||||
//
|
.addText((text) => {
|
||||||
//
|
text.inputEl.type = type;
|
||||||
// // General Database Settings
|
return text
|
||||||
// const GeneralTabs = new SettingGeneralTabs(this.app, this.plugin, this);
|
.setPlaceholder(placeholder)
|
||||||
//
|
.setValue(holderValue)
|
||||||
// GeneralTabs.display();
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
|
||||||
|
await this.plugin.saveSettings();
|
||||||
// Custom Database Settings
|
})
|
||||||
|
});
|
||||||
// containerEl.createEl('h2', {text: i18nConfig.NotionCustomSettingHeader});
|
} else if (type === 'toggle') {
|
||||||
//
|
return new Setting(containerEl)
|
||||||
// new Setting(containerEl)
|
.setName(name)
|
||||||
// .setName(i18nConfig.NotionCustomButton)
|
.setDesc(desc)
|
||||||
// .setDesc(i18nConfig.NotionCustomButtonDesc)
|
.addToggle((toggle) =>
|
||||||
// .addToggle((toggle) =>
|
toggle
|
||||||
// toggle
|
.setValue(holderValue)
|
||||||
// .setValue(this.plugin.settings.CustomButton)
|
.onChange(async (value) => {
|
||||||
// .onChange(async (value) => {
|
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
|
||||||
// this.plugin.settings.CustomButton = value;
|
await this.plugin.saveSettings();
|
||||||
// await this.plugin.saveSettings();
|
await this.plugin.commands.updateCommand();
|
||||||
// })
|
})
|
||||||
// );
|
);
|
||||||
}
|
} else if (type === 'text') {
|
||||||
|
return new Setting(containerEl)
|
||||||
// create a function to create a div with a style for pop over elements
|
.setName(name)
|
||||||
public createStyleDiv(className: string, commandValue: boolean = false) {
|
.setDesc(desc)
|
||||||
return this.containerEl.createDiv(className, (div) => {
|
.addText((text) =>
|
||||||
this.updateSettingEl(div, commandValue);
|
text
|
||||||
});
|
.setPlaceholder(placeholder)
|
||||||
}
|
.setValue(holderValue)
|
||||||
// update the setting display style in the setting tab
|
.onChange(async (value) => {
|
||||||
public updateSettingEl(element: HTMLElement, commandValue: boolean) {
|
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
|
||||||
element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none";
|
await this.plugin.saveSettings();
|
||||||
element.style.paddingTop = commandValue ? "0.75em" : "0";
|
await this.plugin.commands.updateCommand();
|
||||||
element.style.display = commandValue ? "block" : "none";
|
})
|
||||||
element.style.alignItems = "center";
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// function to add one setting element in the setting tab.
|
|
||||||
public createSettingEl(containerEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any, settingsKey: string) {
|
|
||||||
if (type === 'password') {
|
|
||||||
return new Setting(containerEl)
|
|
||||||
.setName(name)
|
|
||||||
.setDesc(desc)
|
|
||||||
.addText((text) => {
|
|
||||||
text.inputEl.type = type;
|
|
||||||
return text
|
|
||||||
.setPlaceholder(placeholder)
|
|
||||||
.setValue(holderValue)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
} else if (type === 'toggle') {
|
|
||||||
return new Setting(containerEl)
|
|
||||||
.setName(name)
|
|
||||||
.setDesc(desc)
|
|
||||||
.addToggle((toggle) =>
|
|
||||||
toggle
|
|
||||||
.setValue(holderValue)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings[settingsKey] = value; // Update the plugin settings directly
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
await this.plugin.commands.updateCommand();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else if (type === 'text') {
|
|
||||||
return new Setting(containerEl)
|
|
||||||
.setName(name)
|
|
||||||
.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() {
|
||||||
@@ -240,8 +211,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")
|
||||||
@@ -253,8 +224,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")
|
||||||
@@ -305,7 +276,7 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
settingEl
|
settingEl
|
||||||
.addButton((button: ButtonComponent): ButtonComponent => {
|
.addButton((button: ButtonComponent): ButtonComponent => {
|
||||||
return button
|
return button
|
||||||
.setTooltip("Delete Database")
|
.setTooltip("Delete Database")
|
||||||
@@ -317,6 +288,8 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
if (modal.data.deleted) {
|
if (modal.data.deleted) {
|
||||||
this.plugin.deleteDatabaseDetails(dbDetails);
|
this.plugin.deleteDatabaseDetails(dbDetails);
|
||||||
|
|
||||||
|
console.log(dbDetails.fullName + " deleted");
|
||||||
|
|
||||||
this.plugin.commands.updateCommand();
|
this.plugin.commands.updateCommand();
|
||||||
|
|
||||||
this.display()
|
this.display()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
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";
|
||||||
|
import { i18nConfig } from "src/lang/I18n";
|
||||||
|
|
||||||
export async function updateYamlInfo(
|
export async function updateYamlInfo(
|
||||||
yamlContent: string,
|
yamlContent: string,
|
||||||
@@ -8,14 +9,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, NotionLinkDisplay } = 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
|
||||||
@@ -31,25 +32,13 @@ export async function updateYamlInfo(
|
|||||||
}
|
}
|
||||||
// add new notionID and link
|
// add new notionID and link
|
||||||
yamlContent[notionIDKey] = id;
|
yamlContent[notionIDKey] = id;
|
||||||
yamlContent[linkKey] = url;
|
(NotionLinkDisplay) ? yamlContent[linkKey] = url : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(url)
|
await navigator.clipboard.writeText(url)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
new Notice(`复制链接失败,请手动复制${error}`)
|
console.log(error)
|
||||||
|
new Notice(`${i18nConfig.CopyErrorMessage}`);
|
||||||
}
|
}
|
||||||
// const __content = yamlContent.__content;
|
|
||||||
// delete yamlContent.__content
|
|
||||||
// const yamlhead = yaml.stringify(yamlContent)
|
|
||||||
// // if yamlhead hava last \n remove it
|
|
||||||
// const yamlhead_remove_n = yamlhead.replace(/\n$/, '')
|
|
||||||
// // if __content have start \n remove it
|
|
||||||
// const __content_remove_n = __content.replace(/^\n/, '')
|
|
||||||
// const content = '---\n' +yamlhead_remove_n +'\n---\n' + __content_remove_n;
|
|
||||||
// try {
|
|
||||||
// await nowFile.vault.modify(nowFile, content)
|
|
||||||
// } catch (error) {
|
|
||||||
// new Notice(`write file error ${error}`)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,14 +16,7 @@ export async function uploadCommandNext(
|
|||||||
app: App,
|
app: App,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const {notionAPI, databaseID} = dbDetails;
|
const { notionAPI, databaseID } = dbDetails;
|
||||||
|
|
||||||
// Check if NNon exists
|
|
||||||
// if (NNon === undefined) {
|
|
||||||
// const NNonmessage = i18nConfig.NNonMissing;
|
|
||||||
// new Notice(NNonmessage);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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 === "") {
|
||||||
@@ -49,12 +42,12 @@ 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);
|
||||||
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
new Notice(`${i18nConfig["sync-success"]}${basename}`);
|
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
||||||
}
|
}
|
||||||
@@ -70,7 +63,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,16 +72,16 @@ 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);
|
||||||
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
new Notice(`${i18nConfig["sync-success"]}${basename}`);
|
new Notice(`${i18nConfig["sync-success"]}${basename}`).noticeEl.style.color = "green";
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
||||||
}
|
}
|
||||||
@@ -104,7 +97,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,16 +106,16 @@ 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);
|
||||||
|
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
new Notice(`${i18nConfig["sync-success"]}${basename}`);
|
new Notice(`${i18nConfig["sync-success"]}${basename}`).noticeEl.style.color = "green";
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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}`,
|
||||||
|
|||||||
@@ -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,19 +78,16 @@ 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 = {
|
||||||
parent: {
|
parent: {
|
||||||
database_id: databaseID,
|
database_id: databaseID,
|
||||||
},
|
},
|
||||||
icon: {
|
|
||||||
emoji: emoji || '📜'
|
|
||||||
},
|
|
||||||
properties: {
|
properties: {
|
||||||
title: {
|
title: {
|
||||||
title: [
|
title: [
|
||||||
@@ -101,25 +98,11 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
tags: {
|
|
||||||
multi_select: tags && true ? tags.map(tag => {
|
|
||||||
return { "name": tag }
|
|
||||||
}) : [],
|
|
||||||
},
|
|
||||||
type: {
|
type: {
|
||||||
select: {
|
select: {
|
||||||
name: type || 'Post'
|
name: type || 'Post'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
slug: {
|
|
||||||
rich_text: [
|
|
||||||
{
|
|
||||||
text: {
|
|
||||||
content: slug || ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
status: {
|
status: {
|
||||||
select: {
|
select: {
|
||||||
name: stats || 'Draft'
|
name: stats || 'Draft'
|
||||||
@@ -130,15 +113,7 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
name: category || 'Obsidian'
|
name: category || 'Obsidian'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
summary: {
|
|
||||||
rich_text: [
|
|
||||||
{
|
|
||||||
text: {
|
|
||||||
content: summary || ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
password: {
|
password: {
|
||||||
rich_text: [
|
rich_text: [
|
||||||
{
|
{
|
||||||
@@ -165,6 +140,52 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
},
|
},
|
||||||
children: childArr,
|
children: childArr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add tags
|
||||||
|
if (tags) {
|
||||||
|
bodyString.properties.tags = {
|
||||||
|
multi_select: tags.map(tag => {
|
||||||
|
return { "name": tag }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add title icon
|
||||||
|
if (emoji) {
|
||||||
|
bodyString.icon = {
|
||||||
|
emoji: emoji
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add slug
|
||||||
|
if (slug) {
|
||||||
|
bodyString.properties.slug = {
|
||||||
|
rich_text: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: slug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if summary is available
|
||||||
|
if (summary) {
|
||||||
|
bodyString.properties.summary = {
|
||||||
|
rich_text: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: summary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (cover) {
|
if (cover) {
|
||||||
bodyString.cover = {
|
bodyString.cover = {
|
||||||
type: "external",
|
type: "external",
|
||||||
@@ -217,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(
|
||||||
|
|||||||
@@ -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 = '';
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -50,46 +50,4 @@ export class UploadBaseCustom {
|
|||||||
return null; // or some other default value, if you prefer
|
return null; // or some other default value, if you prefer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async updateYamlInfo(yamlContent: string, nowFile: TFile, res: any, app: App, settings: any) {
|
|
||||||
// let {url, id} = res.json
|
|
||||||
// // replace www to notionID
|
|
||||||
// const {notionUser} = this.plugin.settings;
|
|
||||||
//
|
|
||||||
// if (notionUser !== "") {
|
|
||||||
// // replace url str "www" to notionID
|
|
||||||
// url = url.replace("www.notion.so", `${notionUser}.notion.site`)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// await app.fileManager.processFrontMatter(nowFile, yamlContent => {
|
|
||||||
// if (yamlContent['notionID']) {
|
|
||||||
// delete yamlContent['notionID']
|
|
||||||
// }
|
|
||||||
// if (yamlContent['link']) {
|
|
||||||
// delete yamlContent['link']
|
|
||||||
// }
|
|
||||||
// // add new notionID and link
|
|
||||||
// yamlContent.notionID = id;
|
|
||||||
// yamlContent.link = url;
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// await navigator.clipboard.writeText(url)
|
|
||||||
// } catch (error) {
|
|
||||||
// new Notice(`复制链接失败,请手动复制${error}`)
|
|
||||||
// }
|
|
||||||
// // const __content = yamlContent.__content;
|
|
||||||
// // delete yamlContent.__content
|
|
||||||
// // const yamlhead = yaml.stringify(yamlContent)
|
|
||||||
// // // if yamlhead hava last \n remove it
|
|
||||||
// // const yamlhead_remove_n = yamlhead.replace(/\n$/, '')
|
|
||||||
// // // if __content have start \n remove it
|
|
||||||
// // const __content_remove_n = __content.replace(/^\n/, '')
|
|
||||||
// // const content = '---\n' +yamlhead_remove_n +'\n---\n' + __content_remove_n;
|
|
||||||
// // try {
|
|
||||||
// // await nowFile.vault.modify(nowFile, content)
|
|
||||||
// // } catch (error) {
|
|
||||||
// // new Notice(`write file error ${error}`)
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -71,6 +71,8 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(bodyString)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await requestUrl({
|
return await requestUrl({
|
||||||
url: `https://api.notion.com/v1/pages`,
|
url: `https://api.notion.com/v1/pages`,
|
||||||
@@ -97,6 +99,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
app: App,
|
app: App,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const options = {
|
const options = {
|
||||||
|
strictImageUrls: true,
|
||||||
notionLimits: {
|
notionLimits: {
|
||||||
truncate: false,
|
truncate: false,
|
||||||
}
|
}
|
||||||
@@ -107,7 +110,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;
|
||||||
|
|
||||||
@@ -121,7 +124,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
} else {
|
} else {
|
||||||
res = await this.createPage(cover, customValues, file2Block);
|
res = await this.createPage(cover, customValues, file2Block);
|
||||||
}
|
}
|
||||||
if (res.status === 200) {
|
if (res && res.status === 200) {
|
||||||
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);
|
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${res.text}`);
|
new Notice(`${res.text}`);
|
||||||
@@ -205,7 +208,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 }],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,11 +221,15 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
|
|
||||||
const properties: { [key: string]: any } = {};
|
const properties: { [key: string]: any } = {};
|
||||||
|
|
||||||
customProperties.forEach(({customName, customType}) => {
|
// Only include custom properties that have values
|
||||||
properties[customName] = this.buildPropertyObject(customName, customType, customValues);
|
customProperties.forEach(({ customName, customType }) => {
|
||||||
|
if (customValues[customName] !== undefined) {
|
||||||
|
properties[customName] = this.buildPropertyObject(customName, customType, customValues);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// console.log(properties)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parent: {
|
parent: {
|
||||||
@@ -233,5 +240,4 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user