mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
@@ -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, category:string, summary:string, paword:string, favicon:string, childArr:any) {
|
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) {
|
||||||
await this.deletePage(notionID)
|
await this.deletePage(notionID)
|
||||||
const res = await this.createPage(title, allowTags, tags, type, slug, stats, category, summary, paword, favicon, childArr)
|
const res = await this.createPage(title, allowTags, tags, type, slug, stats, category, summary, paword, favicon, datetime, childArr)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPage(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, pawrod:string, favicon:string, childArr: any) {
|
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) {
|
||||||
const bodyString:any = {
|
const bodyString:any = {
|
||||||
parent: {
|
parent: {
|
||||||
database_id: this.app.settings.databaseID
|
database_id: this.app.settings.databaseID
|
||||||
@@ -104,6 +104,11 @@ export class Upload2Notion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
date: {
|
||||||
|
date: {
|
||||||
|
start: datetime || new Date().toISOString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
children: childArr,
|
children: childArr,
|
||||||
@@ -136,7 +141,7 @@ export class Upload2Notion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncMarkdownToNotion(title:string, allowTags:boolean, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon: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, 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
|
||||||
@@ -145,9 +150,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, file2Block);
|
res = await this.updatePage(notionID, title, allowTags, 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, file2Block);
|
res = await this.createPage(title, allowTags, 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)
|
||||||
|
|||||||
10
main.ts
10
main.ts
@@ -80,13 +80,12 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { markDownData, nowFile, tags, type, slug, stats, category, summary,paword, favicon } =await this.getNowFileMarkdownContent(this.app);
|
const { markDownData, nowFile, 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, markDownData, nowFile, this.app, this.settings)
|
const res = await upload.syncMarkdownToNotion(basename, allowTags, 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 {
|
||||||
@@ -106,6 +105,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
let summary = ''
|
let summary = ''
|
||||||
let paword = ''
|
let paword = ''
|
||||||
let favicon = ''
|
let favicon = ''
|
||||||
|
let datetime = ''
|
||||||
|
|
||||||
const FileCache = app.metadataCache.getFileCache(nowFile)
|
const FileCache = app.metadataCache.getFileCache(nowFile)
|
||||||
try {
|
try {
|
||||||
@@ -118,6 +118,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
summary = FileCache.frontmatter.summary;
|
summary = FileCache.frontmatter.summary;
|
||||||
paword = FileCache.frontmatter.password;
|
paword = FileCache.frontmatter.password;
|
||||||
favicon = FileCache.frontmatter.icon;
|
favicon = FileCache.frontmatter.icon;
|
||||||
|
datetime = FileCache.frontmatter.date;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
new Notice(langConfig["set-tags-fail"]);
|
new Notice(langConfig["set-tags-fail"]);
|
||||||
@@ -134,7 +135,8 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
category,
|
category,
|
||||||
summary,
|
summary,
|
||||||
paword,
|
paword,
|
||||||
favicon
|
favicon,
|
||||||
|
datetime,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
new Notice(langConfig["open-file"]);
|
new Notice(langConfig["open-file"]);
|
||||||
|
|||||||
Reference in New Issue
Block a user