mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 16:35:57 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8ebab7fcb | ||
|
|
e0ec27ad07 | ||
|
|
85220105b0 | ||
|
|
9afdb24a82 | ||
|
|
3c7ab13995 | ||
|
|
31b72f3bd3 | ||
|
|
ee5aada1b9 | ||
|
|
9e15044f6a | ||
|
|
9d891dae55 | ||
|
|
bc665253ec | ||
|
|
125c75f7c0 | ||
|
|
8248640b5f | ||
|
|
0198898086 | ||
|
|
8c6aea8250 | ||
|
|
a179d3da52 | ||
|
|
569d8eb699 | ||
|
|
2a58dd3258 |
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: release-changelog/action@v1.0.0
|
# uses: saadmk11/changelog-ci@v1.1.2
|
||||||
# with:
|
# with:
|
||||||
# repo-token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
# github_token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
# version: ${{ github.ref }}
|
# release_version: ${{ github.ref }}
|
||||||
# file: 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
|
||||||
|
|||||||
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,18 +1,5 @@
|
|||||||
# Changelog v2.1.0
|
- Update NotionNext function that
|
||||||
|
- `tags`, `titleicon`, `slug` and `summary` are now optional. You can remove them from the frontmatter if you don't need them.
|
||||||
|
|
||||||
## Feature
|
- 更新 NotionNext 同步功能
|
||||||
|
- `tags`, `titleicon`, `slug` 和 `summary` 现在不是必选项了。你可以从你的模板中删除这些字段。
|
||||||
- add confirmation interface for deleting a database
|
|
||||||
- 增加删除数据库的确认界面
|
|
||||||
|
|
||||||
## Fix
|
|
||||||
|
|
||||||
- fix the typo in the edit database modal
|
|
||||||
- improve the logic for the database editing
|
|
||||||
- 修复编辑数据库界面的标题错误
|
|
||||||
- 改进数据库编辑界面的逻辑
|
|
||||||
|
|
||||||
## TODO
|
|
||||||
|
|
||||||
- [ ] add the support for the customised properties of general databases
|
|
||||||
- [ ] 增加对普通数据库自定义属性的支持
|
|
||||||
|
|||||||
147
README.md
147
README.md
@@ -3,27 +3,137 @@
|
|||||||
[](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.**
|
||||||
|
|
||||||
|
**现在支持NotionNext和普通Notion数据库,可自定义数据库列表。**
|
||||||
|
|
||||||
|
## TODO List
|
||||||
|
|
||||||
|
- [ ] Modify the Edit function for the custom properties. 改进自定义属性的编辑功能
|
||||||
|
- [ ] Support group upload with one click 支持一键多数据库上传
|
||||||
|
- [x] Support custom properties for Notion General database. 支持自定义属性
|
||||||
|
- [x] Support preview for database details in plugin settings. 支持预览数据库详情
|
||||||
|
- [x] Support edit for database details in plugin settings. 支持编辑数据库详情
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
You need seven steps to use this plugin in your Obsidian.
|
||||||
|
1. Create a database in your Notion workspace.
|
||||||
|
Open Notion, clink the `+` button on the left side, and 'Add a page' -> select 'Table' -> 'New database'.
|
||||||
|
2. On the right-top corner, click the 'Share' -> 'Publish' -> 'Publish' -> copy the database id from the URL.
|
||||||
|
3. go to [Notion API](https://www.notion.com/my-integrations) to create a new integration, and copy the token.
|
||||||
|
4. Go back to your created Notion database, click the right-top '...' -> connections -> connect to -> find the integration you created and connect it.
|
||||||
|
5. Go to obsidian settings -> community plugins -> search 'NotionNext' -> install it.
|
||||||
|
6. Create a database in the plugin settings, and fill in the database details and all properties you want to sync (**Note: the name of the properties is case-sensitive.**).
|
||||||
|
- There are three type of database that you can use:
|
||||||
|
- NotionNext: the database for the NotionNext template.(**All the properties are in lowercase**)
|
||||||
|
- General: the database for the general Notion database (**Only have `title` and `tags` columns**)
|
||||||
|
- Custom: the database for the custom properties (You can customise the properties you want to sync)
|
||||||
|
7. Create a new note in Obsidian, and fill in the frontmatter with the properties you want to sync.
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
如果你想使用这个插件,你需要完成下边的七个步骤。
|
||||||
|
1. 首先在你的Notion中创建一个数据库。
|
||||||
|
2. 点击右上角的'分享' -> '发布' -> '发布' -> 然后复制URL中的数据库ID。(版本不同,可能id的形式也不同。只需要复制在?之前的纯数字部分应该就可以了)
|
||||||
|
3. 去[Notion API](https://www.notion.com/my-integrations)创建一个新的API,然后复制token。
|
||||||
|
4. 回到你创建的Notion数据库,点击右上角的'...' -> 连接 -> 连接到 -> 把你刚才创建的API绑定到你的数据库
|
||||||
|
5. 回到Obsidian的设置 -> 社区插件 -> 搜索'NotionNext' -> 安装
|
||||||
|
6. 在插件设置中创建一个数据库,然后填写数据库的详情和你想要同步的属性 (**注意:Notion会识别表头的大小写,一定要和notion中的表头保持大小写一致**)。
|
||||||
|
- 你可以使用三种类型的数据库:
|
||||||
|
- NotionNext: 用于NotionNext模板的数据库。(**默认全部小写**)
|
||||||
|
- General: 用于普通的Notion数据库(**只有`title`和`tags`两个属性**)
|
||||||
|
- Custom: 用于自定义属性的数据库(你可以自定义你想要同步的属性)
|
||||||
|
7. 在Obsidian中创建一个新的笔记,然后在frontmatter中写入你想要的属性。
|
||||||
|
|
||||||
|
## Example
|
||||||
|
```plain
|
||||||
|
---
|
||||||
|
# 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, 默认是空
|
||||||
|
status: 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
|
||||||
|
---
|
||||||
|
```
|
||||||
|
<details> <summary> Update </summary>
|
||||||
|
|
||||||
|
### 2.2.5
|
||||||
|
|
||||||
|
- Update NotionNext function that
|
||||||
|
- `tags`, `titleicon`, `slug` and `summary` are now optional. You can remove them from the frontmatter if you don't need them.
|
||||||
|
|
||||||
|
|
||||||
|
### 2.2.3
|
||||||
|
|
||||||
|
- Fix a bug that 'text' property cannot be synchronized. 修复了一个无法同步'text'属性的bug。
|
||||||
|
|
||||||
|
### 2.2.2
|
||||||
|
|
||||||
|
- Fix the setting description of database. 修复数据库设置的描述错误。
|
||||||
|
|
||||||
|
### 2.2.1
|
||||||
|
|
||||||
|
- improve the localisation for the custom properties setting. 改进自定义属性设置的本地化。
|
||||||
|
|
||||||
|
**Warning: the edit function for the custom properties is not perfect for now. You need to re-enter all the properties if you want to edit the properties.**
|
||||||
|
|
||||||
|
**注意:自定义属性的编辑功能现在还不完善。如果你想编辑属性,你需要重新输入所有的属性。**
|
||||||
|
|
||||||
|
### 2.2.0 (Big Update)
|
||||||
|
|
||||||
|
- add the support for custom properties in the Notion General database. 支持自定义属性
|
||||||
|
- [x] `title`, which is the first column of the database
|
||||||
|
- [x] 'Text'
|
||||||
|
- [x] 'Number'
|
||||||
|
- [x] 'Date'
|
||||||
|
- [x] 'Checkbox'
|
||||||
|
- [x] 'Select'
|
||||||
|
- [x] 'Multi-select'
|
||||||
|
- [x] 'URL'
|
||||||
|
- [x] 'Email'
|
||||||
|
- [x] 'Phone'
|
||||||
|
- [x] 'File' (**Only support external embedded files**)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|

|
||||||
|
- Once you create the properties, you can preview the database details in the plugin settings.
|
||||||
|

|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Acknowledgement
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
Thus, based on the [original author's work](https://github.com/EasyChris/obsidian-to-notion), I've added a feature to match the [NotionNext](https://github.com/tangly1024/NotionNext) template. This way, you can edit directly in Obsidian and publish with a single click after organizing.
|
Thus, based on the [original author's work](https://github.com/EasyChris/obsidian-to-notion), I've added a feature to match the [NotionNext](https://github.com/tangly1024/NotionNext) template. This way, you can edit directly in Obsidian and publish with a single click after organizing.
|
||||||
|
|
||||||
**Now, support both NotionNext and General databases.**
|
---
|
||||||
|
|
||||||
**现在支持NotionNext和普通Notion数据库。**
|
<details> <summary> Archive Update </summary>
|
||||||
|
|
||||||
## TODO List
|
|
||||||
|
|
||||||
- [ ] Support custom properties for Notion General database. 支持自定义属性
|
|
||||||
- [x] Support preview for database details in plugin settings. 支持预览数据库详情
|
|
||||||
- [x] Support edit for database details in plugin settings. 支持编辑数据库详情
|
|
||||||
|
|
||||||
## Update
|
|
||||||
|
|
||||||
### 2.1.0
|
### 2.1.0
|
||||||
|
|
||||||
@@ -161,7 +271,9 @@ If you turn off the button for the NotionNext database, you won't see the option
|
|||||||
|
|
||||||
- [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.
|
- [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
|
</details>
|
||||||
|
|
||||||
|
<details> <summary> Previous How to Use </summary>
|
||||||
|
|
||||||
### Precautions
|
### Precautions
|
||||||
|
|
||||||
@@ -253,9 +365,11 @@ Usage of the template is as follows:
|
|||||||
**Plugin preview is shown below**
|
**Plugin preview is shown below**
|
||||||

|

|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Original README.md**
|
<details> <summary> Original README.md </summary>
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
@@ -429,10 +543,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)
|
||||||
@@ -449,3 +559,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.1.2",
|
"version": "2.2.5",
|
||||||
"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.1.2",
|
"version": "2.2.5",
|
||||||
"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",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
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 { 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";
|
||||||
|
|
||||||
@@ -94,11 +94,11 @@ export default class RibbonCommands {
|
|||||||
await uploadCommandGeneral(this.plugin, this.plugin.settings, dbDetails, this.plugin.app);
|
await uploadCommandGeneral(this.plugin, this.plugin.settings, dbDetails, this.plugin.app);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// else if (dbDetails.format === 'custom') {
|
else if (dbDetails.format === 'custom') {
|
||||||
// editorCallback = async (editor, view) => {
|
editorCallback = async (editor, view) => {
|
||||||
// await uploadCommandGeneral(this.plugin, dbDetails, this.plugin.app);
|
await uploadCommandCustom(this.plugin, this.plugin.settings, dbDetails, this.plugin.app);
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|
||||||
this.Ncommand.push({ id: commandId, name: commandName, editorCallback });
|
this.Ncommand.push({ id: commandId, name: commandName, editorCallback });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ 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:
|
||||||
@@ -65,4 +66,11 @@ export const en = {
|
|||||||
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",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,10 @@ 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]です",
|
||||||
@@ -57,4 +58,11 @@ export const ja = {
|
|||||||
NotionCustomSettingHeader: "Notionカスタムデータベース設定",
|
NotionCustomSettingHeader: "Notionカスタムデータベース設定",
|
||||||
NotionCustomButton: "Notionカスタマイズコマンドの切り替え",
|
NotionCustomButton: "Notionカスタマイズコマンドの切り替え",
|
||||||
NotionCustomButtonDesc: "このオプションを開くと、Notionカスタムデータベース同期コマンドがコマンドパレットに表示されます",
|
NotionCustomButtonDesc: "このオプションを開くと、Notionカスタムデータベース同期コマンドがコマンドパレットに表示されます",
|
||||||
|
CustomPropertyName: "カスタムプロパティ名",
|
||||||
|
CustomPropertyFirstColumn: "最初の列のカスタムプロパティ名",
|
||||||
|
CustomPropertyFirstColumnDesc: "最初の列のカスタムプロパティ名を入力してください",
|
||||||
|
CustomProperty: "カスタムプロパティ",
|
||||||
|
AddCustomProperty: "カスタムプロパティを追加",
|
||||||
|
AddNewProperty: "新しいプロパティを追加",
|
||||||
|
AddNewPropertyDesc: "新しいプロパティを追加してください",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ 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:
|
||||||
@@ -60,4 +61,11 @@ export const zh = {
|
|||||||
NotionCustomSettingHeader: "Notion 自定义数据库设置",
|
NotionCustomSettingHeader: "Notion 自定义数据库设置",
|
||||||
NotionCustomButton: "Notion 自定义数据库同步命令开关",
|
NotionCustomButton: "Notion 自定义数据库同步命令开关",
|
||||||
NotionCustomButtonDesc: "打开此选项,同步到自定义数据库命令将显示在命令面板中",
|
NotionCustomButtonDesc: "打开此选项,同步到自定义数据库命令将显示在命令面板中",
|
||||||
|
CustomPropertyName: "自定义属性名",
|
||||||
|
CustomPropertyFirstColumn: "第一列属性名",
|
||||||
|
CustomPropertyFirstColumnDesc: "第一列必须为标题属性名",
|
||||||
|
CustomProperty: "自定义属性",
|
||||||
|
AddCustomProperty: "添加自定义属性",
|
||||||
|
AddNewProperty: "添加新属性",
|
||||||
|
AddNewPropertyDesc: "添加一个和Notion数据库匹配的新属性",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,162 @@
|
|||||||
|
import {App, Modal, Setting} from "obsidian";
|
||||||
|
import ObsidianSyncNotionPlugin from "../main";
|
||||||
|
import {ObsidianSettingTab} from "./settingTabs";
|
||||||
|
import {i18nConfig} from "../lang/I18n";
|
||||||
|
|
||||||
|
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(i18nConfig.CustomPropertyFirstColumn)
|
||||||
|
.setDesc(i18nConfig.CustomPropertyFirstColumnDesc)
|
||||||
|
|
||||||
|
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(i18nConfig.CustomProperty + (propertyIndex))
|
||||||
|
|
||||||
|
propertyLine.addText((text) => {
|
||||||
|
text
|
||||||
|
.setPlaceholder(i18nConfig.CustomPropertyName)
|
||||||
|
.setValue("")
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.properties[propertyIndex].customName = value; // Update the customValue of the specific property
|
||||||
|
});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
propertyLine.addDropdown((dropdown) => {
|
||||||
|
dropdown
|
||||||
|
// .addOption("none", '')
|
||||||
|
.addOption("text", "Text")
|
||||||
|
.addOption("number", "Number")
|
||||||
|
.addOption("select", "Select")
|
||||||
|
.addOption("multi_select", "Multi-Select")
|
||||||
|
.addOption("date", "Date")
|
||||||
|
// .addOption("person", "Person")
|
||||||
|
.addOption("files", "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("")
|
||||||
|
.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(i18nConfig.AddCustomProperty);
|
||||||
|
|
||||||
|
let {contentEl} = this;
|
||||||
|
contentEl.empty();
|
||||||
|
|
||||||
|
const customDiv = contentEl.createDiv("custom-div");
|
||||||
|
|
||||||
|
new Setting(customDiv)
|
||||||
|
.setName(i18nConfig.AddNewProperty)
|
||||||
|
.setDesc(i18nConfig.AddNewPropertyDesc)
|
||||||
|
.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {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 {
|
||||||
dataTemp: Record<string, any> = {
|
dataTemp: Record<string, any> = {
|
||||||
@@ -21,6 +22,7 @@ export class EditModal extends SettingModal {
|
|||||||
customTitleButtonTemp: false,
|
customTitleButtonTemp: false,
|
||||||
// customTitleButtonTempInd: false,
|
// customTitleButtonTempInd: false,
|
||||||
customTitleNameTemp: '',
|
customTitleNameTemp: '',
|
||||||
|
customPropertiesTemp: [],
|
||||||
// customTitleNameTempInd: false,
|
// customTitleNameTempInd: false,
|
||||||
// customValues: '',
|
// customValues: '',
|
||||||
savedTemp: false,
|
savedTemp: false,
|
||||||
@@ -42,6 +44,7 @@ export class EditModal extends SettingModal {
|
|||||||
customTitleButtonPrev: false,
|
customTitleButtonPrev: false,
|
||||||
// customTitleButtonPrevInd: false,
|
// customTitleButtonPrevInd: false,
|
||||||
customTitleNamePrev: '',
|
customTitleNamePrev: '',
|
||||||
|
customPropertiesPrev: [],
|
||||||
// customTitleNamePrevInd: false,
|
// customTitleNamePrevInd: false,
|
||||||
// customValues: '',
|
// customValues: '',
|
||||||
savedPrev: false,
|
savedPrev: false,
|
||||||
@@ -67,6 +70,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.customValues = dbDetails.customValues;
|
// this.dataTemp.customValues = dbDetails.customValues;
|
||||||
this.dataTemp.savedTemp = dbDetails.saved;
|
this.dataTemp.savedTemp = dbDetails.saved;
|
||||||
|
|
||||||
@@ -79,6 +83,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.dataTemp.customValues = dbDetails.customValues;
|
// this.dataTemp.customValues = dbDetails.customValues;
|
||||||
this.dataPrev.savedPrev = dbDetails.saved;
|
this.dataPrev.savedPrev = dbDetails.saved;
|
||||||
}
|
}
|
||||||
@@ -103,7 +108,7 @@ export class EditModal extends SettingModal {
|
|||||||
.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.dataTemp.databaseFormatTemp)
|
.setValue(this.dataTemp.databaseFormatTemp)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.dataTemp.databaseFormatTemp = value;
|
this.dataTemp.databaseFormatTemp = value;
|
||||||
@@ -172,9 +177,9 @@ export class EditModal extends SettingModal {
|
|||||||
.setDesc(i18nConfig.NotionCustomTitleDesc)
|
.setDesc(i18nConfig.NotionCustomTitleDesc)
|
||||||
.addToggle((toggle) =>
|
.addToggle((toggle) =>
|
||||||
toggle
|
toggle
|
||||||
.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)
|
||||||
|
|
||||||
@@ -187,15 +192,15 @@ export class EditModal extends SettingModal {
|
|||||||
|
|
||||||
|
|
||||||
// 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') {
|
||||||
@@ -211,70 +216,46 @@ export class EditModal extends SettingModal {
|
|||||||
// 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 === '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.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
|
|
||||||
this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.dataTemp.tagButtonTemp, 'dataTemp','tagButtonTemp')
|
|
||||||
|
|
||||||
// add custom title button
|
|
||||||
|
|
||||||
new Setting(nextTabs)
|
|
||||||
.setName(i18nConfig.NotionCustomTitle)
|
|
||||||
.setDesc(i18nConfig.NotionCustomTitleDesc)
|
|
||||||
.addToggle((toggle) =>
|
|
||||||
toggle
|
|
||||||
.setValue(this.dataTemp.CustomTitleButtonTemp)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.dataTemp.CustomTitleButtonTemp = value;
|
|
||||||
|
|
||||||
this.updateSettingEl(CustomNameEl, value)
|
|
||||||
|
|
||||||
// this.updateSettingEl(CustomValuesEl, value)
|
|
||||||
|
|
||||||
// await this.plugin.saveSettings();
|
|
||||||
// await this.plugin.commands.updateCommand();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// add custom title name
|
|
||||||
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')
|
|
||||||
|
|
||||||
// // add custom values
|
|
||||||
// const CustomValuesEl = this.createStyleDiv('custom-values', (this.dataTemp.CustomTitleButton), nextTabs);
|
|
||||||
// new Setting(CustomValuesEl)
|
|
||||||
// .setName(i18nConfig.NotionCustomValues)
|
|
||||||
// .setDesc(i18nConfig.NotionCustomValuesDesc)
|
|
||||||
// .addTextArea((text) => {
|
|
||||||
// return text
|
|
||||||
// .setPlaceholder(i18nConfig.NotionCustomValuesText)
|
|
||||||
// .setValue(this.dataTemp.CustomValues)
|
|
||||||
// .onChange(async (value) => {
|
|
||||||
// this.dataTemp.CustomValues = value;
|
|
||||||
// await this.plugin.saveSettings();
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
// add api key
|
// add api key
|
||||||
const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton, nextTabs);
|
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.dataTemp.notionAPITemp, 'dataTemp', 'notionAPITemp')
|
||||||
this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.dataTemp.notionAPITemp, 'dataTemp','notionAPITemp')
|
|
||||||
|
|
||||||
// add database id
|
// add database id
|
||||||
const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton, nextTabs);
|
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.DatabaseIDDesc, 'password', i18nConfig.DatabaseIDText, this.dataTemp.databaseIDTemp, 'dataTemp', 'databaseIDTemp')
|
||||||
this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.dataTemp.databaseIDTemp, 'dataTemp', 'databaseIDTemp')
|
|
||||||
|
// add new property button
|
||||||
|
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 = () => {
|
||||||
|
|
||||||
|
this.renderCustomPreview(customModal.properties, nextTabs)
|
||||||
|
this.dataTemp.customPropertiesTemp = customModal.properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
customModal.open();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,10 +116,24 @@ export class PreviewModal extends Modal {
|
|||||||
|
|
||||||
dbIdSetting.settingEl.style.display = 'none'; // Hide initially
|
dbIdSetting.settingEl.style.display = 'none'; // Hide initially
|
||||||
|
|
||||||
|
// Preview the custom properties
|
||||||
|
|
||||||
|
if (this.dbDetails.format === 'custom') {
|
||||||
|
|
||||||
|
const customPropertiesEl = new Setting(previewEl)
|
||||||
|
customPropertiesEl
|
||||||
|
.setName('Custom Properties')
|
||||||
|
.addTextArea(text => text
|
||||||
|
.setValue(JSON.stringify(this.dbDetails.customProperties, null, 2))
|
||||||
|
.setDisabled(true));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
this.display()
|
this.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import {
|
|||||||
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 class SettingModal extends Modal {
|
export class SettingModal extends Modal {
|
||||||
@@ -21,6 +22,7 @@ export class SettingModal extends Modal {
|
|||||||
tagButton: true,
|
tagButton: true,
|
||||||
customTitleButton: false,
|
customTitleButton: false,
|
||||||
customTitleName: '',
|
customTitleName: '',
|
||||||
|
customProperties: [],
|
||||||
// customValues: '',
|
// customValues: '',
|
||||||
saved: false,
|
saved: false,
|
||||||
};
|
};
|
||||||
@@ -31,6 +33,7 @@ export class SettingModal extends Modal {
|
|||||||
super(app);
|
super(app);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.settingTab = settingTab;
|
this.settingTab = settingTab;
|
||||||
|
this.properties = [];
|
||||||
if (dbDetails) {
|
if (dbDetails) {
|
||||||
this.data.databaseFormat = dbDetails.format;
|
this.data.databaseFormat = dbDetails.format;
|
||||||
this.data.databaseFullName = dbDetails.fullName;
|
this.data.databaseFullName = dbDetails.fullName;
|
||||||
@@ -40,6 +43,7 @@ export class SettingModal extends Modal {
|
|||||||
this.data.tagButton = dbDetails.tagButton;
|
this.data.tagButton = dbDetails.tagButton;
|
||||||
this.data.customTitleButton = dbDetails.customTitleButton;
|
this.data.customTitleButton = dbDetails.customTitleButton;
|
||||||
this.data.customTitleName = dbDetails.customTitleName;
|
this.data.customTitleName = dbDetails.customTitleName;
|
||||||
|
this.data.customProperties = dbDetails.customProperties;
|
||||||
// this.data.customValues = dbDetails.customValues;
|
// this.data.customValues = dbDetails.customValues;
|
||||||
this.data.saved = dbDetails.saved;
|
this.data.saved = dbDetails.saved;
|
||||||
}
|
}
|
||||||
@@ -51,14 +55,13 @@ 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) {
|
if (this.data.saved) {
|
||||||
new Setting(settingDiv)
|
new Setting(settingDiv)
|
||||||
.setName(i18nConfig.databaseFormat)
|
.setName(i18nConfig.databaseFormat)
|
||||||
@@ -68,7 +71,7 @@ export class SettingModal extends Modal {
|
|||||||
.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;
|
||||||
@@ -89,7 +92,7 @@ export class SettingModal extends Modal {
|
|||||||
.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;
|
||||||
@@ -103,29 +106,28 @@ export class SettingModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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.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.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,16 +137,16 @@ 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')
|
||||||
|
|
||||||
// add abbreviate name
|
// add abbreviate name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'data','databaseAbbreviateName')
|
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'data', 'databaseAbbreviateName')
|
||||||
|
|
||||||
// tag button
|
// tag button
|
||||||
this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.data.tagButton, 'data','tagButton')
|
this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.data.tagButton, 'data', 'tagButton')
|
||||||
|
|
||||||
// add custom title button
|
// add custom title button
|
||||||
|
|
||||||
@@ -153,9 +155,9 @@ export class SettingModal extends Modal {
|
|||||||
.setDesc(i18nConfig.NotionCustomTitleDesc)
|
.setDesc(i18nConfig.NotionCustomTitleDesc)
|
||||||
.addToggle((toggle) =>
|
.addToggle((toggle) =>
|
||||||
toggle
|
toggle
|
||||||
.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)
|
||||||
|
|
||||||
@@ -168,113 +170,99 @@ export class SettingModal extends Modal {
|
|||||||
|
|
||||||
|
|
||||||
// add custom title name
|
// add custom title name
|
||||||
const CustomNameEl = this.createStyleDiv('custom-name', (this.data.CustomTitleButton), nextTabs);
|
const CustomNameEl = this.createStyleDiv('custom-name', (this.data.customTitleButton), nextTabs);
|
||||||
this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.data.CustomTitleName, 'data','CustomTitleName')
|
this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.data.customTitleName, 'data', 'customTitleName')
|
||||||
|
|
||||||
|
|
||||||
// add api key
|
// add api key
|
||||||
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')
|
||||||
|
|
||||||
// add abbreviate name
|
// add abbreviate name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'data','databaseAbbreviateName')
|
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'data', 'databaseAbbreviateName')
|
||||||
|
|
||||||
// add api key
|
// add api key
|
||||||
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 === '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')
|
||||||
|
|
||||||
// add abbreviate name
|
// add abbreviate name
|
||||||
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'data','databaseAbbreviateName')
|
this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'data', 'databaseAbbreviateName')
|
||||||
|
|
||||||
// tag button
|
|
||||||
this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.data.tagButton,'data', 'tagButton')
|
|
||||||
|
|
||||||
// add custom title button
|
|
||||||
|
|
||||||
new Setting(nextTabs)
|
|
||||||
.setName(i18nConfig.NotionCustomTitle)
|
|
||||||
.setDesc(i18nConfig.NotionCustomTitleDesc)
|
|
||||||
.addToggle((toggle) =>
|
|
||||||
toggle
|
|
||||||
.setValue(this.data.CustomTitleButton)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.data.CustomTitleButton = value;
|
|
||||||
|
|
||||||
this.updateSettingEl(CustomNameEl, value)
|
|
||||||
|
|
||||||
// this.updateSettingEl(CustomValuesEl, value)
|
|
||||||
|
|
||||||
// await this.plugin.saveSettings();
|
|
||||||
// await this.plugin.commands.updateCommand();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// add custom title name
|
|
||||||
const CustomNameEl = this.createStyleDiv('custom-name', (this.data.CustomTitleButton), nextTabs);
|
|
||||||
this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.data.CustomTitleName,'data', 'CustomTitleName')
|
|
||||||
|
|
||||||
// // add custom values
|
|
||||||
// const CustomValuesEl = this.createStyleDiv('custom-values', (this.data.CustomTitleButton), nextTabs);
|
|
||||||
// new Setting(CustomValuesEl)
|
|
||||||
// .setName(i18nConfig.NotionCustomValues)
|
|
||||||
// .setDesc(i18nConfig.NotionCustomValuesDesc)
|
|
||||||
// .addTextArea((text) => {
|
|
||||||
// return text
|
|
||||||
// .setPlaceholder(i18nConfig.NotionCustomValuesText)
|
|
||||||
// .setValue(this.data.CustomValues)
|
|
||||||
// .onChange(async (value) => {
|
|
||||||
// this.data.CustomValues = value;
|
|
||||||
// await this.plugin.saveSettings();
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
// add api key
|
// add api key
|
||||||
const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton, nextTabs);
|
this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'data', 'notionAPI')
|
||||||
this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI,'data', 'notionAPI')
|
|
||||||
|
|
||||||
// add database id
|
// add database id
|
||||||
const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton, nextTabs);
|
this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.DatabaseIDDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'data', 'databaseID')
|
||||||
this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'data', 'databaseID')
|
|
||||||
|
// add new property button
|
||||||
|
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 = () => {
|
||||||
|
|
||||||
|
this.renderCustomPreview(customModal.properties, nextTabs)
|
||||||
|
this.data.customProperties = customModal.properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
customModal.open();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
// add console log to check if the modal is opened
|
// add console log to check if the modal is opened
|
||||||
this.display()
|
this.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderCustomPreview(properties: any[], nextTabs: HTMLElement) {
|
||||||
|
const previewContainer = nextTabs.createDiv('preview-container');
|
||||||
|
|
||||||
|
properties.forEach((property: { customName: any; customType: any; }) => {
|
||||||
|
const propertyEl = previewContainer.createEl('div', {cls: 'property-preview'});
|
||||||
|
propertyEl.createEl('span', {text: `Property: ${property.customName}, Type: ${property.customType}`});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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) {
|
||||||
return parentEl.createDiv(className, (div) => {
|
return parentEl.createDiv(className, (div) => {
|
||||||
this.updateSettingEl(div, commandValue);
|
this.updateSettingEl(div, commandValue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the setting display style in the setting tab
|
// update the setting display style in the setting tab
|
||||||
public updateSettingEl(element: HTMLElement, commandValue: boolean) {
|
public updateSettingEl(element: HTMLElement, commandValue: boolean) {
|
||||||
element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none";
|
element.style.borderTop = commandValue ? "1px solid var(--background-modifier-border)" : "none";
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export interface PluginSettings {
|
|||||||
proxy: string;
|
proxy: string;
|
||||||
GeneralButton: boolean;
|
GeneralButton: boolean;
|
||||||
tagButton: boolean;
|
tagButton: boolean;
|
||||||
CustomTitleButton: boolean;
|
customTitleButton: boolean;
|
||||||
CustomTitleName: string;
|
customTitleName: string;
|
||||||
notionAPIGeneral: string;
|
notionAPIGeneral: string;
|
||||||
databaseIDGeneral: string;
|
databaseIDGeneral: string;
|
||||||
CustomButton: boolean;
|
CustomButton: boolean;
|
||||||
@@ -37,6 +37,7 @@ export interface DatabaseDetails {
|
|||||||
tagButton: boolean;
|
tagButton: boolean;
|
||||||
customTitleButton: boolean;
|
customTitleButton: boolean;
|
||||||
customTitleName: string;
|
customTitleName: string;
|
||||||
|
customProperties:{ customName: string, customType: string }[];
|
||||||
// customValues: string;
|
// customValues: string;
|
||||||
saved: boolean;
|
saved: boolean;
|
||||||
}
|
}
|
||||||
@@ -50,8 +51,8 @@ export const DEFAULT_SETTINGS: PluginSettings = {
|
|||||||
proxy: "",
|
proxy: "",
|
||||||
GeneralButton: true,
|
GeneralButton: true,
|
||||||
tagButton: true,
|
tagButton: true,
|
||||||
CustomTitleButton: false,
|
customTitleButton: false,
|
||||||
CustomTitleName: "",
|
customTitleName: "",
|
||||||
notionAPIGeneral: "",
|
notionAPIGeneral: "",
|
||||||
databaseIDGeneral: "",
|
databaseIDGeneral: "",
|
||||||
CustomButton: false,
|
CustomButton: false,
|
||||||
@@ -107,6 +108,7 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
tagButton: modal.data.tagButton,
|
tagButton: modal.data.tagButton,
|
||||||
customTitleButton: modal.data.customTitleButton,
|
customTitleButton: modal.data.customTitleButton,
|
||||||
customTitleName: modal.data.customTitleName,
|
customTitleName: modal.data.customTitleName,
|
||||||
|
customProperties: modal.data.customProperties,
|
||||||
// customValues: modal.data.customValues,
|
// customValues: modal.data.customValues,
|
||||||
saved: modal.data.saved,
|
saved: modal.data.saved,
|
||||||
}
|
}
|
||||||
@@ -271,6 +273,7 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
tagButton: modal.dataTemp.tagButtonTemp,
|
tagButton: modal.dataTemp.tagButtonTemp,
|
||||||
customTitleButton: modal.dataTemp.customTitleButtonTemp,
|
customTitleButton: modal.dataTemp.customTitleButtonTemp,
|
||||||
customTitleName: modal.dataTemp.customTitleNameTemp,
|
customTitleName: modal.dataTemp.customTitleNameTemp,
|
||||||
|
customProperties: modal.dataTemp.customPropertiesTemp,
|
||||||
// customValues: modal.data.customValues,
|
// customValues: modal.data.customValues,
|
||||||
saved: modal.dataTemp.savedTemp,
|
saved: modal.dataTemp.savedTemp,
|
||||||
}
|
}
|
||||||
@@ -284,6 +287,7 @@ export class ObsidianSettingTab extends PluginSettingTab {
|
|||||||
tagButton: modal.dataPrev.tagButtonPrev,
|
tagButton: modal.dataPrev.tagButtonPrev,
|
||||||
customTitleButton: modal.dataPrev.customTitleButtonPrev,
|
customTitleButton: modal.dataPrev.customTitleButtonPrev,
|
||||||
customTitleName: modal.dataPrev.customTitleNamePrev,
|
customTitleName: modal.dataPrev.customTitleNamePrev,
|
||||||
|
customProperties: modal.dataPrev.customPropertiesPrev,
|
||||||
// customValues: modal.data.customValues,
|
// customValues: modal.data.customValues,
|
||||||
saved: modal.dataPrev.savedPrev,
|
saved: modal.dataPrev.savedPrev,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { App, Notice, TFile } from "obsidian";
|
import { App, Notice, TFile } from "obsidian";
|
||||||
import ObsidianSyncNotionPlugin from "../main";
|
import ObsidianSyncNotionPlugin from "../main";
|
||||||
import {DatabaseDetails, PluginSettings} from "../ui/settingTabs";
|
import {DatabaseDetails} from "../ui/settingTabs";
|
||||||
|
|
||||||
export async function updateYamlInfo(
|
export async function updateYamlInfo(
|
||||||
yamlContent: string,
|
yamlContent: string,
|
||||||
|
|||||||
@@ -1,118 +1,131 @@
|
|||||||
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,
|
||||||
settings: PluginSettings,
|
settings: PluginSettings,
|
||||||
dbDetails: DatabaseDetails,
|
dbDetails: DatabaseDetails,
|
||||||
app: App,
|
app: App,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const { notionAPI, databaseID } = dbDetails;
|
const {notionAPI, databaseID} = dbDetails;
|
||||||
|
|
||||||
// Check if NNon exists
|
// Check if NNon exists
|
||||||
// if (NNon === undefined) {
|
// if (NNon === undefined) {
|
||||||
// const NNonmessage = i18nConfig.NNonMissing;
|
// const NNonmessage = i18nConfig.NNonMissing;
|
||||||
// new Notice(NNonmessage);
|
// new Notice(NNonmessage);
|
||||||
// return;
|
// 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 === "") {
|
||||||
const setAPIMessage = i18nConfig["set-api-id"];
|
const setAPIMessage = i18nConfig["set-api-id"];
|
||||||
new Notice(setAPIMessage);
|
new Notice(setAPIMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { markDownData, nowFile, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime } = await getNowFileMarkdownContentNext(app, settings)
|
const {
|
||||||
|
markDownData,
|
||||||
|
nowFile,
|
||||||
|
emoji,
|
||||||
|
cover,
|
||||||
|
tags,
|
||||||
|
type,
|
||||||
|
slug,
|
||||||
|
stats,
|
||||||
|
category,
|
||||||
|
summary,
|
||||||
|
paword,
|
||||||
|
favicon,
|
||||||
|
datetime
|
||||||
|
} = 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-success"]}${basename}`);
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export async function uploadCommandGeneral(
|
export async function uploadCommandGeneral(
|
||||||
plugin: ObsidianSyncNotionPlugin,
|
plugin: ObsidianSyncNotionPlugin,
|
||||||
settings: PluginSettings,
|
settings: PluginSettings,
|
||||||
dbDetails: DatabaseDetails,
|
dbDetails: DatabaseDetails,
|
||||||
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 === "") {
|
||||||
const setAPIMessage = i18nConfig["set-api-id"];
|
const setAPIMessage = i18nConfig["set-api-id"];
|
||||||
new Notice(setAPIMessage);
|
new Notice(setAPIMessage);
|
||||||
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}`);
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function uploadCommandCustom(
|
export async function uploadCommandCustom(
|
||||||
plugin: ObsidianSyncNotionPlugin,
|
plugin: ObsidianSyncNotionPlugin,
|
||||||
settings: PluginSettings,
|
settings: PluginSettings,
|
||||||
dbDetails: DatabaseDetails,
|
dbDetails: DatabaseDetails,
|
||||||
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 === "") {
|
||||||
const setAPIMessage = i18nConfig["set-api-id"];
|
const setAPIMessage = i18nConfig["set-api-id"];
|
||||||
new Notice(setAPIMessage);
|
new Notice(setAPIMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { markDownData, nowFile, cover, tags ,customValues} = await getNowFileMarkdownContentCustom(app, settings)
|
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(basename, cover, tags, 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}`);
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]}${basename}`, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,89 +7,90 @@ 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;
|
||||||
notion: Client;
|
notion: Client;
|
||||||
agent: any;
|
agent: any;
|
||||||
dbDetails: DatabaseDetails
|
dbDetails: DatabaseDetails
|
||||||
constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
|
|
||||||
this.plugin = plugin;
|
constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
|
||||||
|
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',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': 'Bearer ' + notionAPI,
|
'Authorization': 'Bearer ' + notionAPI,
|
||||||
'Notion-Version': '2022-06-28',
|
'Notion-Version': '2022-06-28',
|
||||||
},
|
},
|
||||||
body: ''
|
body: ''
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
if (response.json.cover && response.json.cover.external) {
|
if (response.json.cover && response.json.cover.external) {
|
||||||
return response.json.cover.external.url;
|
return response.json.cover.external.url;
|
||||||
} else {
|
} else {
|
||||||
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) {
|
// async updateYamlInfo(yamlContent: string, nowFile: TFile, res: any, app: App, settings: any) {
|
||||||
// let {url, id} = res.json
|
// let {url, id} = res.json
|
||||||
// // replace www to notionID
|
// // replace www to notionID
|
||||||
// const {notionUser} = this.plugin.settings;
|
// const {notionUser} = this.plugin.settings;
|
||||||
//
|
//
|
||||||
// if (notionUser !== "") {
|
// if (notionUser !== "") {
|
||||||
// // replace url str "www" to notionID
|
// // replace url str "www" to notionID
|
||||||
// url = url.replace("www.notion.so", `${notionUser}.notion.site`)
|
// url = url.replace("www.notion.so", `${notionUser}.notion.site`)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// await app.fileManager.processFrontMatter(nowFile, yamlContent => {
|
// await app.fileManager.processFrontMatter(nowFile, yamlContent => {
|
||||||
// if (yamlContent['notionID']) {
|
// if (yamlContent['notionID']) {
|
||||||
// delete yamlContent['notionID']
|
// delete yamlContent['notionID']
|
||||||
// }
|
// }
|
||||||
// if (yamlContent['link']) {
|
// if (yamlContent['link']) {
|
||||||
// delete yamlContent['link']
|
// delete yamlContent['link']
|
||||||
// }
|
// }
|
||||||
// // add new notionID and link
|
// // add new notionID and link
|
||||||
// yamlContent.notionID = id;
|
// yamlContent.notionID = id;
|
||||||
// yamlContent.link = url;
|
// yamlContent.link = url;
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
// try {
|
// try {
|
||||||
// await navigator.clipboard.writeText(url)
|
// await navigator.clipboard.writeText(url)
|
||||||
// } catch (error) {
|
// } catch (error) {
|
||||||
// new Notice(`复制链接失败,请手动复制${error}`)
|
// new Notice(`复制链接失败,请手动复制${error}`)
|
||||||
// }
|
// }
|
||||||
// // const __content = yamlContent.__content;
|
// // const __content = yamlContent.__content;
|
||||||
// // delete yamlContent.__content
|
// // delete yamlContent.__content
|
||||||
// // const yamlhead = yaml.stringify(yamlContent)
|
// // const yamlhead = yaml.stringify(yamlContent)
|
||||||
// // // if yamlhead hava last \n remove it
|
// // // if yamlhead hava last \n remove it
|
||||||
// // const yamlhead_remove_n = yamlhead.replace(/\n$/, '')
|
// // const yamlhead_remove_n = yamlhead.replace(/\n$/, '')
|
||||||
// // // if __content have start \n remove it
|
// // // if __content have start \n remove it
|
||||||
// // const __content_remove_n = __content.replace(/^\n/, '')
|
// // const __content_remove_n = __content.replace(/^\n/, '')
|
||||||
// // const content = '---\n' +yamlhead_remove_n +'\n---\n' + __content_remove_n;
|
// // const content = '---\n' +yamlhead_remove_n +'\n---\n' + __content_remove_n;
|
||||||
// // try {
|
// // try {
|
||||||
// // await nowFile.vault.modify(nowFile, content)
|
// // await nowFile.vault.modify(nowFile, content)
|
||||||
// // } catch (error) {
|
// // } catch (error) {
|
||||||
// // new Notice(`write file error ${error}`)
|
// // new Notice(`write file error ${error}`)
|
||||||
// // }
|
// // }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
const frontmasster =
|
const frontmasster =
|
||||||
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
||||||
const {abName} = this.dbDetails
|
const {abName} = this.dbDetails
|
||||||
const notionIDKey = `${abName}-NotionID`;
|
const notionIDKey = `NotionID-${abName}`;
|
||||||
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,31 +3,31 @@ 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,
|
||||||
settings: PluginSettings,
|
settings: PluginSettings,
|
||||||
) {
|
) {
|
||||||
const nowFile = app.workspace.getActiveFile();
|
const nowFile = app.workspace.getActiveFile();
|
||||||
let cover = '';
|
let cover = '';
|
||||||
let tags = [];
|
let tags = [];
|
||||||
|
|
||||||
const FileCache = app.metadataCache.getFileCache(nowFile);
|
const FileCache = app.metadataCache.getFileCache(nowFile);
|
||||||
try {
|
try {
|
||||||
cover = FileCache.frontmatter.coverurl;
|
cover = FileCache.frontmatter.coverurl;
|
||||||
tags = FileCache.frontmatter.tags;
|
tags = FileCache.frontmatter.tags;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
new Notice(i18nConfig["set-tags-fail"]);
|
new Notice(i18nConfig["set-tags-fail"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nowFile) {
|
if (nowFile) {
|
||||||
const markDownData = await nowFile.vault.read(nowFile);
|
const markDownData = await nowFile.vault.read(nowFile);
|
||||||
return {
|
return {
|
||||||
markDownData,
|
markDownData,
|
||||||
nowFile,
|
nowFile,
|
||||||
cover,
|
cover,
|
||||||
tags,
|
tags,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
new Notice(i18nConfig["open-file"]);
|
new Notice(i18nConfig["open-file"]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,9 +88,6 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
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",
|
||||||
@@ -228,7 +249,7 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
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 = `${abName}-NotionID`;
|
const notionIDKey = `NotionID-${abName}`;
|
||||||
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { App, Notice, requestUrl, TFile } from "obsidian";
|
import {App, Notice, requestUrl, TFile} from "obsidian";
|
||||||
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, 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 {
|
||||||
@@ -21,15 +20,13 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
// 暂时就直接删除,新建一个page
|
// 暂时就直接删除,新建一个page
|
||||||
async updatePage(
|
async updatePage(
|
||||||
notionID: string,
|
notionID: string,
|
||||||
title: string,
|
|
||||||
cover: string,
|
cover: string,
|
||||||
tags: string[],
|
|
||||||
customValues: Record<string, string>,
|
customValues: Record<string, string>,
|
||||||
childArr: any,
|
childArr: any,
|
||||||
) {
|
) {
|
||||||
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
|
||||||
@@ -39,56 +36,22 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
cover = databaseCover;
|
cover = databaseCover;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.createPage(title, cover, tags, customValues, childArr);
|
return await this.createPage(cover, customValues, childArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPage(
|
async createPage(
|
||||||
title: string,
|
|
||||||
cover: string,
|
cover: string,
|
||||||
tags: string[],
|
|
||||||
customValues: Record<string, string>,
|
customValues: Record<string, string>,
|
||||||
childArr: any,
|
childArr: any,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const {
|
const {
|
||||||
databaseID,
|
databaseID,
|
||||||
customTitleButton,
|
customProperties,
|
||||||
customTitleName,
|
|
||||||
tagButton,
|
|
||||||
notionAPI
|
notionAPI
|
||||||
} = this.dbDetails;
|
} = this.dbDetails;
|
||||||
|
|
||||||
const bodyString: any = {
|
const bodyString: any = this.buildBodyString(customProperties, customValues, childArr);
|
||||||
parent: {
|
|
||||||
database_id: databaseID,
|
|
||||||
},
|
|
||||||
properties: {
|
|
||||||
[customTitleButton
|
|
||||||
? customTitleName
|
|
||||||
: "title"]: {
|
|
||||||
title: [
|
|
||||||
{
|
|
||||||
text: {
|
|
||||||
content: title,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
...(Object.keys(customValues).reduce((acc, key) => {
|
|
||||||
acc[key] = {
|
|
||||||
rich_text: [
|
|
||||||
{
|
|
||||||
text: {
|
|
||||||
content: customValues[key] || '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
return acc;
|
|
||||||
}, {} as Record<string, { rich_text: { text: { content: string } }[] } >)),
|
|
||||||
},
|
|
||||||
children: childArr,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (cover) {
|
if (cover) {
|
||||||
bodyString.cover = {
|
bodyString.cover = {
|
||||||
@@ -127,9 +90,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async syncMarkdownToNotionCustom(
|
async syncMarkdownToNotionCustom(
|
||||||
title: string,
|
|
||||||
cover: string,
|
cover: string,
|
||||||
tags: string[],
|
|
||||||
customValues: Record<string, string>,
|
customValues: Record<string, string>,
|
||||||
markdown: string,
|
markdown: string,
|
||||||
nowFile: TFile,
|
nowFile: TFile,
|
||||||
@@ -146,19 +107,19 @@ 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 notionID = frontmasster ? frontmasster.notionID : null;
|
const {abName} = this.dbDetails
|
||||||
|
const notionIDKey = `NotionID-${abName}`;
|
||||||
|
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
||||||
|
|
||||||
if (notionID) {
|
if (notionID) {
|
||||||
res = await this.updatePage(
|
res = await this.updatePage(
|
||||||
notionID,
|
notionID,
|
||||||
title,
|
|
||||||
cover,
|
cover,
|
||||||
tags,
|
|
||||||
customValues,
|
customValues,
|
||||||
file2Block,
|
file2Block,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
res = await this.createPage(title, cover, tags, customValues, file2Block);
|
res = await this.createPage(cover, customValues, file2Block);
|
||||||
}
|
}
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);
|
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);
|
||||||
@@ -167,4 +128,109 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private buildPropertyObject(customName: string, customType: string, customValues: Record<string, any>) {
|
||||||
|
const value = customValues[customName] || '';
|
||||||
|
|
||||||
|
switch (customType) {
|
||||||
|
case "title":
|
||||||
|
return {
|
||||||
|
title: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
case "rich_text":
|
||||||
|
return {
|
||||||
|
rich_text: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: value || '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
case "date":
|
||||||
|
return {
|
||||||
|
date: {
|
||||||
|
start: value || new Date().toISOString(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
case "number":
|
||||||
|
return {
|
||||||
|
number: Number(value),
|
||||||
|
};
|
||||||
|
case "phone_number":
|
||||||
|
return {
|
||||||
|
phone_number: value,
|
||||||
|
};
|
||||||
|
case "email":
|
||||||
|
return {
|
||||||
|
email: value,
|
||||||
|
};
|
||||||
|
case "url":
|
||||||
|
return {
|
||||||
|
url: value,
|
||||||
|
};
|
||||||
|
case "files":
|
||||||
|
return {
|
||||||
|
files: Array.isArray(value) ? value.map(url => ({
|
||||||
|
name: url,
|
||||||
|
type: "external",
|
||||||
|
external: {
|
||||||
|
url: url,
|
||||||
|
},
|
||||||
|
})) : [
|
||||||
|
{
|
||||||
|
name: value,
|
||||||
|
type: "external",
|
||||||
|
external: {
|
||||||
|
url: value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
case "checkbox":
|
||||||
|
return {
|
||||||
|
checkbox: Boolean(value) || false,
|
||||||
|
};
|
||||||
|
case "select":
|
||||||
|
return {
|
||||||
|
select: {
|
||||||
|
name: value,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
case "multi_select":
|
||||||
|
return {
|
||||||
|
multi_select: Array.isArray(value) ? value.map(item => ({name: item})) : [{name: value}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildBodyString(
|
||||||
|
customProperties: { customName: string; customType: string }[],
|
||||||
|
customValues: Record<string, string>,
|
||||||
|
childArr: any,
|
||||||
|
) {
|
||||||
|
|
||||||
|
const properties: { [key: string]: any } = {};
|
||||||
|
|
||||||
|
customProperties.forEach(({customName, customType}) => {
|
||||||
|
properties[customName] = this.buildPropertyObject(customName, customType, customValues);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
parent: {
|
||||||
|
database_id: this.dbDetails.databaseID,
|
||||||
|
},
|
||||||
|
properties,
|
||||||
|
children: childArr,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,57 @@
|
|||||||
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 {DatabaseDetails} from "../../ui/settingTabs";
|
||||||
|
|
||||||
export async function getNowFileMarkdownContentCustom(
|
export async function getNowFileMarkdownContentCustom(
|
||||||
app: App,
|
app: App,
|
||||||
settings: PluginSettings,
|
dbDetails: DatabaseDetails,
|
||||||
) {
|
) {
|
||||||
const nowFile = app.workspace.getActiveFile();
|
const nowFile = app.workspace.getActiveFile();
|
||||||
let cover = '';
|
if (!nowFile) {
|
||||||
let tags = [];
|
new Notice(i18nConfig["open-file"]);
|
||||||
let customValues: Record<string, string> = {};
|
return;
|
||||||
|
}
|
||||||
|
let cover = '';
|
||||||
|
let customValues: Record<string, any> = {};
|
||||||
|
|
||||||
const FileCache = app.metadataCache.getFileCache(nowFile);
|
const FileCache = app.metadataCache.getFileCache(nowFile);
|
||||||
try {
|
try {
|
||||||
cover = FileCache.frontmatter.coverurl;
|
cover = FileCache.frontmatter.coverurl;
|
||||||
tags = FileCache.frontmatter.tags;
|
|
||||||
|
|
||||||
// split the CustomValues into an array
|
// Get custom property names from dbDetails excluding the title type property
|
||||||
const customValuesNames = settings.CustomValues.split('\n').map(value => value.trim());
|
const customPropertyNames = dbDetails.customProperties
|
||||||
|
.filter(property => property.customType !== 'title') // Exclude 'title' type property
|
||||||
|
.map(property => property.customName);
|
||||||
|
|
||||||
// get the custom values from the frontmatter
|
// Extract custom values from the front matter based on the names
|
||||||
customValuesNames.forEach(valueName => {
|
customPropertyNames.forEach(propertyName => {
|
||||||
customValues[valueName] = FileCache.frontmatter[valueName];
|
if (FileCache.frontmatter && FileCache.frontmatter[propertyName] !== undefined) {
|
||||||
});
|
customValues[propertyName] = FileCache.frontmatter[propertyName];
|
||||||
} catch (error) {
|
}
|
||||||
new Notice(i18nConfig["set-tags-fail"]);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (nowFile) {
|
// Check if any of the customProperties has a customType of 'title'
|
||||||
const markDownData = await nowFile.vault.read(nowFile);
|
const titleProperty = dbDetails.customProperties.find(property => property.customType === 'title');
|
||||||
return {
|
|
||||||
markDownData,
|
// If a 'title' type property exists, use the file's basename as its value
|
||||||
nowFile,
|
if (titleProperty) {
|
||||||
cover,
|
customValues[titleProperty.customName] = nowFile.basename; // Use 'basename' for the file name without extension
|
||||||
tags,
|
}
|
||||||
customValues,
|
|
||||||
};
|
} catch (error) {
|
||||||
} else {
|
new Notice(i18nConfig["set-tags-fail"]);
|
||||||
new Notice(i18nConfig["open-file"]);
|
}
|
||||||
return;
|
|
||||||
}
|
if (nowFile) {
|
||||||
|
const markDownData = await nowFile.vault.read(nowFile);
|
||||||
|
return {
|
||||||
|
markDownData,
|
||||||
|
nowFile,
|
||||||
|
cover,
|
||||||
|
customValues,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
new Notice(i18nConfig["open-file"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user