mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
Added right share url link
This commit is contained in:
@@ -82,29 +82,41 @@ export class Upload2Notion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncMarkdownToNotion(title:string, markdown: string, nowFile: TFile, app:App): Promise<any> {
|
async syncMarkdownToNotion(title:string, markdown: string, nowFile: TFile, app:App, settings:any): Promise<any> {
|
||||||
let res:any
|
let res:any
|
||||||
const file2Block = markdownToBlocks(markdown);
|
const yamlObj:any = yamlFrontMatter.loadFront(markdown);
|
||||||
|
const __content = yamlObj.__content
|
||||||
|
const file2Block = markdownToBlocks(__content);
|
||||||
const frontmasster =await app.metadataCache.getFileCache(nowFile)?.frontmatter
|
const frontmasster =await app.metadataCache.getFileCache(nowFile)?.frontmatter
|
||||||
const notionID = frontmasster ? frontmasster.notionId : null
|
const notionID = frontmasster ? frontmasster.notionId : null
|
||||||
|
|
||||||
if(notionID){
|
if(notionID){
|
||||||
res = await this.updatePage(notionID, title, file2Block);
|
res = await this.updatePage(notionID, title, file2Block);
|
||||||
|
console.log(res)
|
||||||
} else {
|
} else {
|
||||||
res = await this.createPage(title, file2Block);
|
res = await this.createPage(title, file2Block);
|
||||||
|
console.log(res)
|
||||||
}
|
}
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
await this.updateYamlInfo(markdown, nowFile, res, app)
|
await this.updateYamlInfo(markdown, nowFile, res, app, settings)
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${res.text}`)
|
new Notice(`${res.text}`)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateYamlInfo(yamlContent: string, nowFile: TFile, res: any,app:App) {
|
async updateYamlInfo(yamlContent: string, nowFile: TFile, res: any,app:App, settings:any) {
|
||||||
const yamlObj:any = yamlFrontMatter.loadFront(yamlContent);
|
const yamlObj:any = yamlFrontMatter.loadFront(yamlContent);
|
||||||
const {url, id} = res.json
|
let {url, id} = res.json
|
||||||
|
// replace www to notionID
|
||||||
|
console.log(app)
|
||||||
|
const {notionID} = settings;
|
||||||
|
if(notionID!=="") {
|
||||||
|
// replace url str "www" to notionID
|
||||||
|
url = url.replace("www.notion.so", `${notionID}.notion.site`)
|
||||||
|
}
|
||||||
yamlObj.link = url;
|
yamlObj.link = url;
|
||||||
|
console.log(url)
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(url)
|
await navigator.clipboard.writeText(url)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
18
main.ts
18
main.ts
@@ -22,6 +22,7 @@ interface PluginSettings {
|
|||||||
notionAPI: string;
|
notionAPI: string;
|
||||||
databaseID: string;
|
databaseID: string;
|
||||||
bannerUrl: string;
|
bannerUrl: string;
|
||||||
|
notionID: string;
|
||||||
proxy: string;
|
proxy: string;
|
||||||
langConfig: any;
|
langConfig: any;
|
||||||
}
|
}
|
||||||
@@ -30,6 +31,7 @@ const DEFAULT_SETTINGS: PluginSettings = {
|
|||||||
notionAPI: "",
|
notionAPI: "",
|
||||||
databaseID: "",
|
databaseID: "",
|
||||||
bannerUrl: "",
|
bannerUrl: "",
|
||||||
|
notionID: "",
|
||||||
proxy: "",
|
proxy: "",
|
||||||
langConfig: NoticeMConfig( window.localStorage.getItem('language') || 'en')
|
langConfig: NoticeMConfig( window.localStorage.getItem('language') || 'en')
|
||||||
};
|
};
|
||||||
@@ -84,7 +86,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
|
|||||||
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, markDownData,nowFile, this.app)
|
const res = await upload.syncMarkdownToNotion(basename, markDownData,nowFile, this.app, this.settings)
|
||||||
if(res.status === 200){
|
if(res.status === 200){
|
||||||
new Notice(`${this.settings.langConfig["sync-success"]}${basename}`)
|
new Notice(`${this.settings.langConfig["sync-success"]}${basename}`)
|
||||||
}else {
|
}else {
|
||||||
@@ -179,5 +181,19 @@ class SampleSettingTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName("Notion ID(optional)")
|
||||||
|
.setDesc("Your notion ID(optional),share link likes:https://username.notion.site/,your notion id is [username]")
|
||||||
|
.addText((text) =>
|
||||||
|
text
|
||||||
|
.setPlaceholder("Enter notion ID(options) ")
|
||||||
|
.setValue(this.plugin.settings.notionID)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.notionID = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user