successful category and summary

This commit is contained in:
Jiaxin Peng
2023-08-09 19:48:03 +01:00
parent 1d22f2e741
commit f9f30df7ea
2 changed files with 28 additions and 8 deletions

View File

@@ -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, stats:string, childArr:any) { async updatePage(notionID:string, title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, childArr:any) {
await this.deletePage(notionID) await this.deletePage(notionID)
const res = await this.createPage(title, allowTags, tags, type, slug, stats, childArr) const res = await this.createPage(title, allowTags, tags, type, slug, stats, category, summary, childArr)
return res return res
} }
async createPage(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, childArr: any) { async createPage(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, childArr: any) {
const bodyString:any = { const bodyString:any = {
parent: { parent: {
database_id: this.app.settings.databaseID database_id: this.app.settings.databaseID
@@ -72,6 +72,20 @@ export class Upload2Notion {
select: { select: {
name: stats || 'Draft' name: stats || 'Draft'
} }
},
category: {
select: {
name: category || 'Obsidian'
}
},
summary: {
rich_text: [
{
text: {
content: summary
}
}
]
} }
}, },
children: childArr, children: childArr,
@@ -104,7 +118,7 @@ export class Upload2Notion {
} }
} }
async syncMarkdownToNotion(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats: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, category:string, summary: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
@@ -113,9 +127,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, file2Block); res = await this.updatePage(notionID, title, allowTags, tags, type, slug, stats, category, summary, file2Block);
} else { } else {
res = await this.createPage(title, allowTags, tags, type, slug, stats, file2Block); res = await this.createPage(title, allowTags, tags, type, slug, stats, category, summary, 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)

10
main.ts
View File

@@ -80,13 +80,13 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
); );
return; return;
} }
const { markDownData, nowFile, tags, type, slug, stats } =await this.getNowFileMarkdownContent(this.app); const { markDownData, nowFile, tags, type, slug, stats, category, summary } =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, markDownData, nowFile, this.app, this.settings) const res = await upload.syncMarkdownToNotion(basename, allowTags, tags, type, slug, stats, category, summary, 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 {
@@ -102,6 +102,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
let type = '' let type = ''
let slug = '' let slug = ''
let stats = '' let stats = ''
let category = ''
let summary = ''
const FileCache = app.metadataCache.getFileCache(nowFile) const FileCache = app.metadataCache.getFileCache(nowFile)
try { try {
@@ -110,6 +112,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
type = FileCache.frontmatter.type; type = FileCache.frontmatter.type;
slug = FileCache.frontmatter.slug; slug = FileCache.frontmatter.slug;
stats = FileCache.frontmatter.stats; stats = FileCache.frontmatter.stats;
category = FileCache.frontmatter.category;
summary = FileCache.frontmatter.summary;
} }
} catch (error) { } catch (error) {
new Notice(langConfig["set-tags-fail"]); new Notice(langConfig["set-tags-fail"]);
@@ -123,6 +127,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
type, type,
slug, slug,
stats, stats,
category,
summary,
}; };
} else { } else {
new Notice(langConfig["open-file"]); new Notice(langConfig["open-file"]);