mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 16:35:57 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2434ddd532 | ||
|
|
55804e491a | ||
|
|
679e7ec4f1 | ||
|
|
9be679f456 | ||
|
|
a0f5d2d51b | ||
|
|
a68a3920ad | ||
|
|
76d3fc9872 | ||
|
|
e3fb50b205 |
4
.github/workflows/CI.yml
vendored
4
.github/workflows/CI.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
- "*"
|
- "*"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
PLUGIN_NAME: obsidian-to-notion
|
PLUGIN_NAME: share-to-notionnext
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -23,4 +23,4 @@ jobs:
|
|||||||
id: build
|
id: build
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
|
|||||||
25
.github/workflows/release.yml
vendored
25
.github/workflows/release.yml
vendored
@@ -6,7 +6,7 @@ on:
|
|||||||
- "*"
|
- "*"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
PLUGIN_NAME: obsidian-to-notion # Change this to match the id of your plugin.
|
PLUGIN_NAME: share-to-notionnext # Change this to match the id of your plugin.
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
VERSION: ${{ github.ref }}
|
VERSION: ${{ github.ref }}
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ github.ref }}
|
tag_name: ${{ github.ref }}
|
||||||
@@ -46,7 +46,7 @@ jobs:
|
|||||||
id: upload-zip
|
id: upload-zip
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_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
|
||||||
@@ -57,7 +57,7 @@ jobs:
|
|||||||
id: upload-main
|
id: upload-main
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_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
|
||||||
@@ -68,20 +68,31 @@ jobs:
|
|||||||
id: upload-manifest
|
id: upload-manifest
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_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
|
||||||
|
id: upload-md
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: ./obsidian_template.md
|
||||||
|
asset_name: template.md
|
||||||
|
asset_content_type: text/markdown
|
||||||
|
|
||||||
# - name: Upload styles.css
|
# - name: Upload styles.css
|
||||||
# id: upload-css
|
# id: upload-css
|
||||||
# uses: actions/upload-release-asset@v1
|
# uses: actions/upload-release-asset@v1
|
||||||
# env:
|
# env:
|
||||||
# GITHUB_TOKEN: ${{ secrets.GITHUB_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: ./styles.css
|
# asset_path: ./styles.css
|
||||||
# asset_name: styles.css
|
# asset_name: styles.css
|
||||||
# asset_content_type: text/css
|
# asset_content_type: text/css
|
||||||
|
|||||||
44
README-zh.md
44
README-zh.md
@@ -1,4 +1,4 @@
|
|||||||
# Obsidian to NotionNext
|
# Obsidian share to NotionNext
|
||||||
感谢[原作者](https://github.com/EasyChris/obsidian-to-notion)开发出了这么好用的插件,能够将obsidian同步到notion。 但是原仓库只能同步Name和Tags信息,如果像我一样通过[NotionNext](https://github.com/tangly1024/NotionNext)来搭建自己的网页,就有一些局限性。每次导入之后都需要进行大量的修改。
|
感谢[原作者](https://github.com/EasyChris/obsidian-to-notion)开发出了这么好用的插件,能够将obsidian同步到notion。 但是原仓库只能同步Name和Tags信息,如果像我一样通过[NotionNext](https://github.com/tangly1024/NotionNext)来搭建自己的网页,就有一些局限性。每次导入之后都需要进行大量的修改。
|
||||||
|
|
||||||
所以我在[原作者](https://github.com/EasyChris/obsidian-to-notion)的基础之上,增加了匹配[NotionNext](https://github.com/tangly1024/NotionNext)模板的功能。这样可以直接在Obsidian编辑,整理好之后一键发布。
|
所以我在[原作者](https://github.com/EasyChris/obsidian-to-notion)的基础之上,增加了匹配[NotionNext](https://github.com/tangly1024/NotionNext)模板的功能。这样可以直接在Obsidian编辑,整理好之后一键发布。
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
### 准备安装
|
### 准备安装
|
||||||
在安装插件之前,你必须配置好了以下内容:
|
在安装插件之前,你必须配置好了以下内容:
|
||||||
|
|
||||||
1. 你的NotionNext数据库。
|
1. 你的NotionNext数据库。
|
||||||
2. 根据原作者的readme.md,配置好了Notion API,并且已经和你的NotionNext仓库关联。
|
2. 根据原作者的readme.md,配置好了Notion API,并且已经和你的NotionNext仓库关联。
|
||||||
3. NotionNext Database ID
|
3. NotionNext Database ID
|
||||||
@@ -25,7 +26,14 @@
|
|||||||
- summary
|
- summary
|
||||||
- password
|
- password
|
||||||
- icon
|
- icon
|
||||||
**如果你是直接复制的NotionNext的模板,这些内容应该已经有了。我在原作者的基础之上对本插件的内容进行了更改,所以你只需要保证你的数据库有如上内容,并且所有的字母都是小写!!!**
|
|
||||||
|
在最新的0.0.6版本,我还增加了以下内容:
|
||||||
|
- titleicon: 标题的emoji图标,暂时只能支持emoji
|
||||||
|
- coverurl: 封面图片的url, url可以是任何一种图片的url, 例如jpg,png,svg等等。
|
||||||
|
|
||||||
|
**如果你是直接复制的NotionNext的模板,这些内容应该已经有了。我在原作者的基础之上对本插件的内容进行了更改,所以你只需要保证你的数据库有如上内容,并且所有的字母都是小写!!!**
|
||||||
|
|
||||||
|
|
||||||
**⚠️⚠️⚠️:表头全部小写!!!顺序无所谓!**
|
**⚠️⚠️⚠️:表头全部小写!!!顺序无所谓!**
|
||||||
|
|
||||||
### 安装插件
|
### 安装插件
|
||||||
@@ -37,24 +45,36 @@
|
|||||||
### 使用插件
|
### 使用插件
|
||||||
在仓库中我上传了一个模板,你可以直接复制到你的模板文件夹中。然后使用Obsidian的模板功能一键生成新笔记。
|
在仓库中我上传了一个模板,你可以直接复制到你的模板文件夹中。然后使用Obsidian的模板功能一键生成新笔记。
|
||||||
|
|
||||||
|
|
||||||
如果你不想使用模板,你也可以直接在Obsidian中创建一个新的文件,然后复制下边的内容。然后保存。
|
如果你不想使用模板,你也可以直接在Obsidian中创建一个新的文件,然后复制下边的内容。然后保存。
|
||||||
```markdown
|
```markdown
|
||||||
---
|
---
|
||||||
type: Post # Post or Page, the default is Post
|
# default value has been set.
|
||||||
slug: test # slug for url, the default is
|
# for any unwanted value, you can delete it or set it to empty.
|
||||||
stats: Draft # Draft, Invisible, Published
|
# for example, if you donot want to set password, you can delete password: "1234" or set it to password: ""
|
||||||
category: test
|
# 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。
|
||||||
summary: this is a summary for test post
|
# 例如你不需要密码选项,你可以将password: "1234"删除,或者将它设置为空。
|
||||||
icon: fa-solid fa-camera # you can ignore this
|
# !!!!!!!!!!!!
|
||||||
password: "1234" # if you donot want to set password, you can delete this line
|
# 现在阶段一定不要修改表头的名字, please do not change the name of the header in YAML front matter
|
||||||
|
# !!!!!!!!!!!!
|
||||||
|
titleicon: 📎 # emoji icon, default is 📜, 默认是📜
|
||||||
|
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty, 默认是空
|
||||||
|
type: Post # Post or Page, default is Post, 默认是Post
|
||||||
|
slug: test # slug for url, default is empty, 默认是空
|
||||||
|
stats: Draft # Draft, Invisible, Published, default is Draft, 默认是Draft
|
||||||
|
category: test # default is 'Obsidian', 默认是'Obsidian'
|
||||||
|
summary: this is a summary for test post # default is empty, 默认是空
|
||||||
|
icon: fa-solid fa-camera # you can ignore this, default is empty, 默认是空,可直接删除
|
||||||
|
password: "1234" # if you donot want to set password, you can delete this line, default is empty, 默认是空,可直接删除
|
||||||
|
# 现在必须开启tags选项,否则会报错
|
||||||
tags:
|
tags:
|
||||||
- test # tags for post
|
- test # tags for post
|
||||||
- web # add more tags if you want
|
- web # add more tags if you want
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
Contents Below
|
Contents Below
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
模板使用如下:
|
模板使用如下:
|
||||||

|

|
||||||
@@ -64,7 +84,9 @@ Contents Below
|
|||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**以下为原README.md**
|
**以下为原README.md**
|
||||||
|
|
||||||
非常感谢原作者的开发,我只是在原作者的基础之上进行了修改,增加了一些功能。如果你觉得这个插件对你有帮助,可以给[原作者](https://github.com/EasyChris/obsidian-to-notion)一个star。
|
非常感谢原作者的开发,我只是在原作者的基础之上进行了修改,增加了一些功能。如果你觉得这个插件对你有帮助,可以给[原作者](https://github.com/EasyChris/obsidian-to-notion)一个star。
|
||||||
|
|
||||||
# Obsidian to Notion
|
# Obsidian to Notion
|
||||||
|
|||||||
41
README.md
41
README.md
@@ -1,5 +1,6 @@
|
|||||||
# Obsidian to NotionNext
|
# Obsidian to NotionNext
|
||||||
[中文文档](README-zh.md)
|
[中文文档](README-zh.md)
|
||||||
|
|
||||||
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 Tags 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 Tags 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.
|
||||||
@@ -26,8 +27,14 @@ Before installing the plugin, you must have set up the following:
|
|||||||
- summary
|
- summary
|
||||||
- password
|
- password
|
||||||
- icon
|
- icon
|
||||||
**If you've directly copied the NotionNext template, these contents should already exist. I've made changes to this plugin based on the original author's work. All you need to ensure is that your database has the above content, and every letter is in lowercase!!!**
|
|
||||||
**⚠️⚠️⚠️: All headers are in lowercase!!! The order doesn't matter!**
|
In version 0.0.6, I also add the following contents:
|
||||||
|
- titleicon: the unique icon for each post, it can only support emoji currently.
|
||||||
|
- cover url: the cover image for each post, it should be end with a type of image, such as .jpg, .png, .gif, etc.
|
||||||
|
|
||||||
|
**If you've directly copied the NotionNext template, these contents should already exist. I've made changes to this plugin based on the original author's work. All you need to ensure is that your database has the above content, and every letter is in lowercase!!!**
|
||||||
|
|
||||||
|
**⚠️⚠️⚠️: All headers are in lowercase!!! The order doesn't matter!**
|
||||||
|
|
||||||
### Plugin Installation
|
### Plugin Installation
|
||||||
1. Close Obsidian.
|
1. Close Obsidian.
|
||||||
@@ -42,19 +49,31 @@ In the repository, I have uploaded a template which you can directly copy into y
|
|||||||
If you don't want to use the template, you can also directly create a new file in Obsidian and then copy the content below. Then save it.
|
If you don't want to use the template, you can also directly create a new file in Obsidian and then copy the content below. Then save it.
|
||||||
```markdown
|
```markdown
|
||||||
---
|
---
|
||||||
type: Post # Post or Page, the default is Post
|
# default value has been set.
|
||||||
slug: test # slug for url, the default is
|
# for any unwanted value, you can delete it or set it to empty.
|
||||||
stats: Draft # Draft, Invisible, Published
|
# for example, if you donot want to set password, you can delete password: "1234" or set it to password: ""
|
||||||
category: test
|
# 我已经在插件中设置了默认值,如果有不需要的选项,可以直接删除。
|
||||||
summary: this is a summary for test post
|
# 例如你不需要密码选项,你可以将password: "1234"删除,或者将它设置为空。
|
||||||
icon: fa-solid fa-camera # you can ignore this
|
# !!!!!!!!!!!!
|
||||||
password: "1234" # if you donot want to set password, you can delete this line
|
# 现在阶段一定不要修改表头的名字, please do not change the name of the header in YAML front matter
|
||||||
|
# !!!!!!!!!!!!
|
||||||
|
titleicon: 📎 # emoji icon, default is 📜, 默认是📜
|
||||||
|
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty, 默认是空
|
||||||
|
type: Post # Post or Page, default is Post, 默认是Post
|
||||||
|
slug: test # slug for url, default is empty, 默认是空
|
||||||
|
stats: Draft # Draft, Invisible, Published, default is Draft, 默认是Draft
|
||||||
|
category: test # default is 'Obsidian', 默认是'Obsidian'
|
||||||
|
summary: this is a summary for test post # default is empty, 默认是空
|
||||||
|
icon: fa-solid fa-camera # you can ignore this, default is empty, 默认是空,可直接删除
|
||||||
|
password: "1234" # if you donot want to set password, you can delete this line, default is empty, 默认是空,可直接删除
|
||||||
|
# 现在必须开启tags选项,否则会报错
|
||||||
tags:
|
tags:
|
||||||
- test # tags for post
|
- test # tags for post
|
||||||
- web # add more tags if you want
|
- web # add more tags if you want
|
||||||
---
|
---
|
||||||
|
|
||||||
Contents Below
|
Contents Below
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage of the template is as follows:
|
Usage of the template is as follows:
|
||||||

|

|
||||||
@@ -63,7 +82,9 @@ Usage of the template is as follows:
|
|||||||

|

|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Original README.md**
|
**Original README.md**
|
||||||
|
|
||||||
Many Thanks for the original author's work. I've only made some changes to the original author's work. If you find this plugin useful, please give the [original author](https://github.com/EasyChris/obsidian-to-notion) a star.
|
Many Thanks for the original author's work. I've only made some changes to the original author's work. If you find this plugin useful, please give the [original author](https://github.com/EasyChris/obsidian-to-notion) a star.
|
||||||
|
|
||||||
# Obsidian to Notion
|
# Obsidian to Notion
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Notice, requestUrl,TFile,normalizePath, App } from "obsidian";
|
import {App, Notice, requestUrl, TFile} from "obsidian";
|
||||||
import { Client } from "@notionhq/client";
|
import {Client} from "@notionhq/client";
|
||||||
import { markdownToBlocks, } from "@tryfabric/martian";
|
import {markdownToBlocks,} from "@tryfabric/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
import * as yaml from "yaml"
|
import * as yaml from "yaml"
|
||||||
import MyPlugin from "main";
|
import MyPlugin from "main";
|
||||||
|
|
||||||
export class Upload2Notion {
|
export class Upload2Notion {
|
||||||
app: MyPlugin;
|
app: MyPlugin;
|
||||||
notion: Client;
|
notion: Client;
|
||||||
@@ -13,32 +14,59 @@ export class Upload2Notion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deletePage(notionID:string){
|
async deletePage(notionID:string){
|
||||||
const response = await requestUrl({
|
return await 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 ' + this.app.settings.notionAPI,
|
'Authorization': 'Bearer ' + this.app.settings.notionAPI,
|
||||||
'Notion-Version': '2022-02-22',
|
'Notion-Version': '2022-06-28',
|
||||||
},
|
},
|
||||||
body: ''
|
body: ''
|
||||||
})
|
})
|
||||||
return response;
|
}
|
||||||
|
|
||||||
|
async getDataBase(databaseID:string){
|
||||||
|
const response = await requestUrl({
|
||||||
|
url: `https://api.notion.com/v1/databases/${databaseID}`,
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + this.app.settings.notionAPI,
|
||||||
|
'Notion-Version': '2022-06-28',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check if cover is present in the JSON response and then get the URL
|
||||||
|
if (response.json.cover && response.json.cover.external) {
|
||||||
|
return response.json.cover.external.url;
|
||||||
|
} else {
|
||||||
|
return null; // or some other default value, if you prefer
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 因为需要解析notion的block进行对比,非常的麻烦,
|
// 因为需要解析notion的block进行对比,非常的麻烦,
|
||||||
// 暂时就直接删除,新建一个page
|
// 暂时就直接删除,新建一个page
|
||||||
async updatePage(notionID:string, title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, childArr:any) {
|
async updatePage(notionID:string, title:string, allowTags:boolean, emoji:string, cover:string, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, childArr:any) {
|
||||||
await this.deletePage(notionID)
|
await this.deletePage(notionID)
|
||||||
const res = await this.createPage(title, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, childArr)
|
|
||||||
return res
|
const databasecover = await this.getDataBase(this.app.settings.databaseID)
|
||||||
|
|
||||||
|
if (cover == null) {
|
||||||
|
cover = databasecover
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.createPage(title, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, childArr)
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPage(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, pawrod:string, favicon:string, datetime:string, childArr: any) {
|
async createPage(title:string, allowTags:boolean, emoji:string, cover:string, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, pawrod:string, favicon:string, datetime:string, childArr: any) {
|
||||||
const bodyString:any = {
|
const bodyString:any = {
|
||||||
parent: {
|
parent: {
|
||||||
database_id: this.app.settings.databaseID
|
database_id: this.app.settings.databaseID
|
||||||
},
|
},
|
||||||
|
icon: {
|
||||||
|
emoji: emoji || '📜'
|
||||||
|
},
|
||||||
properties: {
|
properties: {
|
||||||
title: {
|
title: {
|
||||||
title: [
|
title: [
|
||||||
@@ -63,7 +91,7 @@ export class Upload2Notion {
|
|||||||
rich_text: [
|
rich_text: [
|
||||||
{
|
{
|
||||||
text: {
|
text: {
|
||||||
content: slug || 'obsidian'
|
content: slug || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -113,18 +141,26 @@ export class Upload2Notion {
|
|||||||
},
|
},
|
||||||
children: childArr,
|
children: childArr,
|
||||||
}
|
}
|
||||||
|
if (cover) {
|
||||||
if(this.app.settings.bannerUrl) {
|
|
||||||
bodyString.cover = {
|
bodyString.cover = {
|
||||||
type: "external",
|
type: "external",
|
||||||
external: {
|
external: {
|
||||||
url: this.app.settings.bannerUrl
|
url: cover
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!bodyString.cover && this.app.settings.bannerUrl) {
|
||||||
|
bodyString.cover = {
|
||||||
|
type: "external",
|
||||||
|
external: {
|
||||||
|
url: this.app.settings.bannerUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await requestUrl({
|
return await requestUrl({
|
||||||
url: `https://api.notion.com/v1/pages`,
|
url: `https://api.notion.com/v1/pages`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -135,13 +171,12 @@ export class Upload2Notion {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
})
|
})
|
||||||
return response;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
new Notice(`network error ${error}`)
|
new Notice(`network error ${error}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncMarkdownToNotion(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, markdown: string, nowFile: TFile, app:App, settings:any): Promise<any> {
|
async syncMarkdownToNotion(title:string, allowTags:boolean, emoji:string, cover:string, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, markdown: string, nowFile: TFile, app:App, settings:any): Promise<any> {
|
||||||
let res:any
|
let res:any
|
||||||
const yamlObj:any = yamlFrontMatter.loadFront(markdown);
|
const yamlObj:any = yamlFrontMatter.loadFront(markdown);
|
||||||
const __content = yamlObj.__content
|
const __content = yamlObj.__content
|
||||||
@@ -150,9 +185,9 @@ export class Upload2Notion {
|
|||||||
const notionID = frontmasster ? frontmasster.notionID : null
|
const notionID = frontmasster ? frontmasster.notionID : null
|
||||||
|
|
||||||
if(notionID){
|
if(notionID){
|
||||||
res = await this.updatePage(notionID, title, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, file2Block);
|
res = await this.updatePage(notionID, title, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, file2Block);
|
||||||
} else {
|
} else {
|
||||||
res = await this.createPage(title, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, file2Block);
|
res = await this.createPage(title, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, file2Block);
|
||||||
}
|
}
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
await this.updateYamlInfo(markdown, nowFile, res, app, settings)
|
await this.updateYamlInfo(markdown, nowFile, res, app, settings)
|
||||||
|
|||||||
63
main.ts
63
main.ts
@@ -1,18 +1,7 @@
|
|||||||
import {
|
import {App, Editor, MarkdownView, Notice, Plugin, PluginSettingTab, Setting} from "obsidian";
|
||||||
App,
|
import {addIcons} from 'icon';
|
||||||
Editor,
|
import {Upload2Notion} from "Upload2Notion";
|
||||||
MarkdownView,
|
|
||||||
Modal,
|
|
||||||
Notice,
|
|
||||||
Plugin,
|
|
||||||
PluginSettingTab,
|
|
||||||
Setting,
|
|
||||||
normalizePath
|
|
||||||
} from "obsidian";
|
|
||||||
import {addIcons} from 'icon';
|
|
||||||
import { Upload2Notion } from "Upload2Notion";
|
|
||||||
import {NoticeMConfig} from "Message";
|
import {NoticeMConfig} from "Message";
|
||||||
import { CLIENT_RENEG_LIMIT } from "tls";
|
|
||||||
|
|
||||||
|
|
||||||
// Remember to rename these classes and interfaces!
|
// Remember to rename these classes and interfaces!
|
||||||
@@ -48,7 +37,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
"Share to NotionNext",
|
"Share to NotionNext",
|
||||||
async (evt: MouseEvent) => {
|
async (evt: MouseEvent) => {
|
||||||
// Called when the user clicks the icon.
|
// Called when the user clicks the icon.
|
||||||
this.upload();
|
await this.upload();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -60,7 +49,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
id: "share-to-notionnext",
|
id: "share-to-notionnext",
|
||||||
name: "share to notionnext",
|
name: "share to notionnext",
|
||||||
editorCallback: async (editor: Editor, view: MarkdownView) => {
|
editorCallback: async (editor: Editor, view: MarkdownView) => {
|
||||||
this.upload()
|
await this.upload()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,12 +69,12 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { markDownData, nowFile, tags, type, slug, stats, category, summary, paword, favicon, datetime } =await this.getNowFileMarkdownContent(this.app);
|
const { markDownData, nowFile, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime } =await this.getNowFileMarkdownContent(this.app);
|
||||||
|
|
||||||
if (markDownData) {
|
if (markDownData) {
|
||||||
const { basename } = nowFile;
|
const { basename } = nowFile;
|
||||||
const upload = new Upload2Notion(this);
|
const upload = new Upload2Notion(this);
|
||||||
const res = await upload.syncMarkdownToNotion(basename, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app, this.settings)
|
const res = await upload.syncMarkdownToNotion(basename, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app, this.settings)
|
||||||
if(res.status === 200){
|
if(res.status === 200){
|
||||||
new Notice(`${langConfig["sync-success"]}${basename}`)
|
new Notice(`${langConfig["sync-success"]}${basename}`)
|
||||||
}else {
|
}else {
|
||||||
@@ -97,6 +86,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
async getNowFileMarkdownContent(app: App) {
|
async getNowFileMarkdownContent(app: App) {
|
||||||
const nowFile = app.workspace.getActiveFile();
|
const nowFile = app.workspace.getActiveFile();
|
||||||
const { allowTags } = this.settings;
|
const { allowTags } = this.settings;
|
||||||
|
let emoji = ''
|
||||||
|
let cover = ''
|
||||||
let tags = []
|
let tags = []
|
||||||
let type = ''
|
let type = ''
|
||||||
let slug = ''
|
let slug = ''
|
||||||
@@ -110,6 +101,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
const FileCache = app.metadataCache.getFileCache(nowFile)
|
const FileCache = app.metadataCache.getFileCache(nowFile)
|
||||||
try {
|
try {
|
||||||
if(allowTags) {
|
if(allowTags) {
|
||||||
|
emoji = FileCache.frontmatter.titleicon;
|
||||||
|
cover = FileCache.frontmatter.coverurl;
|
||||||
tags = FileCache.frontmatter.tags;
|
tags = FileCache.frontmatter.tags;
|
||||||
type = FileCache.frontmatter.type;
|
type = FileCache.frontmatter.type;
|
||||||
slug = FileCache.frontmatter.slug;
|
slug = FileCache.frontmatter.slug;
|
||||||
@@ -128,6 +121,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
return {
|
return {
|
||||||
markDownData,
|
markDownData,
|
||||||
nowFile,
|
nowFile,
|
||||||
|
emoji,
|
||||||
|
cover,
|
||||||
tags,
|
tags,
|
||||||
type,
|
type,
|
||||||
slug,
|
slug,
|
||||||
@@ -178,15 +173,14 @@ class SampleSettingTab extends PluginSettingTab {
|
|||||||
.setName("Notion API Token")
|
.setName("Notion API Token")
|
||||||
.setDesc("It's a secret")
|
.setDesc("It's a secret")
|
||||||
.addText((text) =>{
|
.addText((text) =>{
|
||||||
let t = text
|
|
||||||
.setPlaceholder("Enter your Notion API Token")
|
|
||||||
.setValue(this.plugin.settings.notionAPI)
|
|
||||||
.onChange(async (value) => {
|
|
||||||
this.plugin.settings.notionAPI = value;
|
|
||||||
await this.plugin.saveSettings();
|
|
||||||
})
|
|
||||||
// t.inputEl.type = 'password'
|
// t.inputEl.type = 'password'
|
||||||
return t
|
return text
|
||||||
|
.setPlaceholder("Enter your Notion API Token")
|
||||||
|
.setValue(this.plugin.settings.notionAPI)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.notionAPI = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -194,15 +188,14 @@ class SampleSettingTab extends PluginSettingTab {
|
|||||||
.setName("Database ID")
|
.setName("Database ID")
|
||||||
.setDesc("It's a secret")
|
.setDesc("It's a secret")
|
||||||
.addText((text) => {
|
.addText((text) => {
|
||||||
let t = text
|
// t.inputEl.type = 'password'
|
||||||
.setPlaceholder("Enter your Database ID")
|
return text
|
||||||
.setValue(this.plugin.settings.databaseID)
|
.setPlaceholder("Enter your Database ID")
|
||||||
.onChange(async (value) => {
|
.setValue(this.plugin.settings.databaseID)
|
||||||
this.plugin.settings.databaseID = value;
|
.onChange(async (value) => {
|
||||||
await this.plugin.saveSettings();
|
this.plugin.settings.databaseID = value;
|
||||||
})
|
await this.plugin.saveSettings();
|
||||||
// t.inputEl.type = 'password'
|
})
|
||||||
return t
|
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"id": "share-to-notionnext",
|
"id": "share-to-notionnext",
|
||||||
"name": "Share markdown to NotionNext",
|
"name": "Share to NotionNext",
|
||||||
"version": "0.0.2",
|
"version": "0.0.8",
|
||||||
"minAppVersion": "0.0.1",
|
"minAppVersion": "0.0.1",
|
||||||
"description": "This is a plugin for Obsidian. This plugin share obsidian md file to notion with notion api for NotionNext web deploy.",
|
"description": "This is a plugin for Obsidian. This plugin shares obsidian md file to notion with notion api for NotionNext web deploy.",
|
||||||
"author": "jxpeng98",
|
"author": "jxpeng98",
|
||||||
"authorUrl": "https://github.com/jxpeng98/obsidian-to-NotionNext",
|
"authorUrl": "https://github.com/jxpeng98/obsidian-to-NotionNext",
|
||||||
"isDesktopOnly": false
|
"isDesktopOnly": false
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
---
|
|
||||||
type: Post // Post or Page
|
|
||||||
slug: test // slug for url
|
|
||||||
stats: Draft // Draft, Invisible, Published
|
|
||||||
category: test
|
|
||||||
summary: this is a summary for test post
|
|
||||||
icon: fa-solid fa-camera // you can ignore this
|
|
||||||
password: "1234" // if you donot want to set password, you can delete this line
|
|
||||||
tags:
|
|
||||||
- test // tags for post
|
|
||||||
- web // add more tags if you want
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
Contents Below
|
|
||||||
25
obsidian_template.md
Normal file
25
obsidian_template.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
# 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: 📎 # default is 📜, 默认是📜
|
||||||
|
coverurl: https://img.jxpeng.dev/2023/08/843e27a210847f05a0f7cfb121fec100.jpg # default is empty, 默认是空
|
||||||
|
type: Post # Post or Page, default is Post, 默认是Post
|
||||||
|
slug: test # slug for url, default is empty, 默认是空
|
||||||
|
stats: Draft # Draft, Invisible, Published, default is Draft, 默认是Draft
|
||||||
|
category: test # default is 'Obsidian', 默认是'Obsidian'
|
||||||
|
summary: this is a summary for test post # default is empty, 默认是空
|
||||||
|
icon: fa-solid fa-camera # you can ignore this, default is empty, 默认是空,可直接删除
|
||||||
|
password: "1234" # if you donot want to set password, you can delete this line, default is empty, 默认是空,可直接删除
|
||||||
|
# 现在必须开启tags选项,否则会报错
|
||||||
|
tags:
|
||||||
|
- test # tags for post
|
||||||
|
- web # add more tags if you want
|
||||||
|
---
|
||||||
|
|
||||||
|
Contents Below
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "share-to-notionnext",
|
"name": "share-to-notionnext",
|
||||||
"version": "0.0.2",
|
"version": "0.0.8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "This is a plugin for Obsidian. This plugin share obsidian md file to notion with notion api for NotionNext web deploy.",
|
"description": "This is a plugin for Obsidian. This plugin share obsidian md file to notion with notion api for NotionNext web deploy.",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user