mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
success status
This commit is contained in:
@@ -28,13 +28,13 @@ export class Upload2Notion {
|
|||||||
|
|
||||||
// 因为需要解析notion的block进行对比,非常的麻烦,
|
// 因为需要解析notion的block进行对比,非常的麻烦,
|
||||||
// 暂时就直接删除,新建一个page
|
// 暂时就直接删除,新建一个page
|
||||||
async updatePage(notionID:string, title:string, allowTags:boolean, tags:string[], type:string, slug:string, childArr:any) {
|
async updatePage(notionID:string, title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, childArr:any) {
|
||||||
await this.deletePage(notionID)
|
await this.deletePage(notionID)
|
||||||
const res = await this.createPage(title, allowTags, tags, type, slug, childArr)
|
const res = await this.createPage(title, allowTags, tags, type, slug, stats, childArr)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPage(title:string, allowTags:boolean, tags:string[], type:string, slug:string, childArr: any) {
|
async createPage(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, childArr: any) {
|
||||||
const bodyString:any = {
|
const bodyString:any = {
|
||||||
parent: {
|
parent: {
|
||||||
database_id: this.app.settings.databaseID
|
database_id: this.app.settings.databaseID
|
||||||
@@ -67,6 +67,11 @@ export class Upload2Notion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
select: {
|
||||||
|
name: stats || 'Draft'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
children: childArr,
|
children: childArr,
|
||||||
@@ -99,7 +104,7 @@ export class Upload2Notion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncMarkdownToNotion(title:string, allowTags:boolean, tags:string[], type:string, slug:string, markdown: string, nowFile: TFile, app:App, settings:any): Promise<any> {
|
async syncMarkdownToNotion(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats: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
|
||||||
@@ -108,9 +113,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, file2Block);
|
res = await this.updatePage(notionID, title, allowTags, tags, type, slug, stats, file2Block);
|
||||||
} else {
|
} else {
|
||||||
res = await this.createPage(title, allowTags, tags, type, slug, file2Block);
|
res = await this.createPage(title, allowTags, tags, type, slug, stats, 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)
|
||||||
|
|||||||
7
main.ts
7
main.ts
@@ -80,13 +80,13 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { markDownData, nowFile, tags, type, slug } =await this.getNowFileMarkdownContent(this.app);
|
const { markDownData, nowFile, tags, type, slug, stats } =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, markDownData, nowFile, this.app, this.settings)
|
const res = await upload.syncMarkdownToNotion(basename, allowTags, tags, type, slug, stats, 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 {
|
||||||
@@ -101,6 +101,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
let tags = []
|
let tags = []
|
||||||
let type = ''
|
let type = ''
|
||||||
let slug = ''
|
let slug = ''
|
||||||
|
let stats = ''
|
||||||
|
|
||||||
const FileCache = app.metadataCache.getFileCache(nowFile)
|
const FileCache = app.metadataCache.getFileCache(nowFile)
|
||||||
try {
|
try {
|
||||||
@@ -108,6 +109,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
tags = FileCache.frontmatter.tags;
|
tags = FileCache.frontmatter.tags;
|
||||||
type = FileCache.frontmatter.type;
|
type = FileCache.frontmatter.type;
|
||||||
slug = FileCache.frontmatter.slug;
|
slug = FileCache.frontmatter.slug;
|
||||||
|
stats = FileCache.frontmatter.stats;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
new Notice(langConfig["set-tags-fail"]);
|
new Notice(langConfig["set-tags-fail"]);
|
||||||
@@ -120,6 +122,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
tags,
|
tags,
|
||||||
type,
|
type,
|
||||||
slug,
|
slug,
|
||||||
|
stats,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
new Notice(langConfig["open-file"]);
|
new Notice(langConfig["open-file"]);
|
||||||
|
|||||||
Reference in New Issue
Block a user