mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 16:35:57 +08:00
Added update
This commit is contained in:
@@ -68,6 +68,8 @@ A share link will be automatically generated after successful upload
|
|||||||
- [x] support for custom page banner
|
- [x] support for custom page banner
|
||||||
- [ ] update the exsit page
|
- [ ] update the exsit page
|
||||||
- [ ] transfer the bi-link format like [[]] into the format that Notion supports.
|
- [ ] transfer the bi-link format like [[]] into the format that Notion supports.
|
||||||
|
- [ ] support for mult language
|
||||||
|
- [ ] support for auto copy the share link to clipboard
|
||||||
|
|
||||||
# Buy me a cup of coffee.
|
# Buy me a cup of coffee.
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,30 @@ export class Upload2Notion {
|
|||||||
constructor(app: MyPlugin) {
|
constructor(app: MyPlugin) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deletePage(notionID:string){
|
||||||
|
const response = await requestUrl({
|
||||||
|
url: `https://api.notion.com/v1/blocks/${notionID}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.app.settings.notionAPI,
|
||||||
|
'Notion-Version': '2022-02-22',
|
||||||
|
},
|
||||||
|
body: ''
|
||||||
|
})
|
||||||
|
console.log(response)
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 因为需要解析notion的block进行对比,非常的麻烦,
|
||||||
|
// 暂时就直接删除,新建一个page
|
||||||
|
async updatePage(notionID:string, title:string, childArr:any) {
|
||||||
|
await this.deletePage(notionID)
|
||||||
|
const res = await this.createPage(title, childArr)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
async createPage(title:string, childArr: any) {
|
async createPage(title:string, childArr: any) {
|
||||||
const bodyString:any = {
|
const bodyString:any = {
|
||||||
parent: {
|
parent: {
|
||||||
@@ -56,10 +80,18 @@ export class Upload2Notion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async syncMarkdownToNotion(title:string, markdown: string, fullPath:string): Promise<any> {
|
async syncMarkdownToNotion(title:string, markdown: string, fullPath:string): Promise<any> {
|
||||||
|
let res:any
|
||||||
const yamlObj:any = yamlFrontMatter.loadFront(markdown);
|
const yamlObj:any = yamlFrontMatter.loadFront(markdown);
|
||||||
|
console.log(yamlObj)
|
||||||
const __content = yamlObj.__content
|
const __content = yamlObj.__content
|
||||||
const file2md = markdownToBlocks(__content);
|
const file2Block = markdownToBlocks(__content);
|
||||||
const res = await this.createPage(title, file2md);
|
const {notionID} = yamlObj;
|
||||||
|
if(notionID){
|
||||||
|
res = await this.updatePage(notionID, title, file2Block);
|
||||||
|
} else {
|
||||||
|
res = await this.createPage(title, file2Block);
|
||||||
|
}
|
||||||
|
console.log(res,'===')
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
this.updateYamlInfo(markdown, fullPath, res)
|
this.updateYamlInfo(markdown, fullPath, res)
|
||||||
}
|
}
|
||||||
@@ -68,8 +100,9 @@ export class Upload2Notion {
|
|||||||
|
|
||||||
async updateYamlInfo(yamlContent: string, fullPath: string, res: any) {
|
async updateYamlInfo(yamlContent: string, fullPath: string, res: any) {
|
||||||
const yamlObj:any = yamlFrontMatter.loadFront(yamlContent);
|
const yamlObj:any = yamlFrontMatter.loadFront(yamlContent);
|
||||||
const {url} = res.json
|
const {url, id} = res.json
|
||||||
yamlObj.link = url;
|
yamlObj.link = url;
|
||||||
|
yamlObj.notionID = id;
|
||||||
const __content = yamlObj.__content;
|
const __content = yamlObj.__content;
|
||||||
delete yamlObj.__content
|
delete yamlObj.__content
|
||||||
const yamlhead = yaml.stringify(yamlObj)
|
const yamlhead = yaml.stringify(yamlObj)
|
||||||
|
|||||||
3
main.ts
3
main.ts
@@ -45,6 +45,9 @@ export default class MyPlugin extends Plugin {
|
|||||||
"Share to notion",
|
"Share to notion",
|
||||||
async (evt: MouseEvent) => {
|
async (evt: MouseEvent) => {
|
||||||
// Called when the user clicks the icon.
|
// Called when the user clicks the icon.
|
||||||
|
console.log(this,window.localStorage.getItem('language'))
|
||||||
|
|
||||||
|
|
||||||
this.upload();
|
this.upload();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user