diff --git a/Upload2Notion.ts b/Upload2Notion.ts index 509c645..b4a5955 100644 --- a/Upload2Notion.ts +++ b/Upload2Notion.ts @@ -1,6 +1,6 @@ -import { App, requestUrl } from "obsidian"; +import { requestUrl } from "obsidian"; import { Client } from "@notionhq/client"; -import { markdownToBlocks, markdownToRichText } from "@tryfabric/martian"; +import { markdownToBlocks, } from "@tryfabric/martian"; import * as fs from "fs"; import * as yamlFrontMatter from "yaml-front-matter"; import * as yaml from "yaml" @@ -13,10 +13,11 @@ export class Upload2Notion { constructor(app: MyPlugin) { this.app = app; } - async createPage(title:string, childArr: any) { const bodyString = { - "parent": { "database_id": this.app.settings.databaseID }, + parent: { + database_id: this.app.settings.databaseID + }, properties: { Name: { title: [ @@ -35,7 +36,7 @@ export class Upload2Notion { method: 'POST', headers: { 'Content-Type': 'application/json', - 'User-Agent': 'obsidian.md', + // 'User-Agent': 'obsidian.md', 'Authorization': 'Bearer ' + this.app.settings.notionAPI, 'Notion-Version': '2021-08-16', }, diff --git a/icon.ts b/icon.ts new file mode 100644 index 0000000..cb01294 --- /dev/null +++ b/icon.ts @@ -0,0 +1,17 @@ +import { addIcon } from 'obsidian'; + +const icons: Record = { + 'notion-logo': ` + + + + + + ` +}; + +export const addIcons = (): void => { + Object.keys(icons).forEach((key) => { + addIcon(key, icons[key]); + }); +}; diff --git a/main.ts b/main.ts index cf460f1..5b6e261 100644 --- a/main.ts +++ b/main.ts @@ -13,8 +13,8 @@ import { } from "obsidian"; import { join } from "path"; import * as fs from "fs"; +import {addIcons} from 'icon'; import { Upload2Notion } from "Upload2Notion"; -// import {Upload2Notion} from "./Upload2Notion"; // Remember to rename these classes and interfaces! @@ -32,14 +32,14 @@ const DEFAULT_SETTINGS: MyPluginSettings = { export default class MyPlugin extends Plugin { settings: MyPluginSettings; - + async onload() { await this.loadSettings(); - + addIcons(); // This creates an icon in the left ribbon. const ribbonIconEl = this.addRibbonIcon( - "dice", - "share to notion", + "notion-logo", + "Share to notion", async (evt: MouseEvent) => { // Called when the user clicks the icon. this.upload(); @@ -64,10 +64,6 @@ export default class MyPlugin extends Plugin { // This adds a settings tab so the user can configure various aspects of the plugin this.addSettingTab(new SampleSettingTab(this.app, this)); - // When registering intervals, this function will automatically clear the interval when the plugin is disabled. - this.registerInterval( - window.setInterval(() => console.log("setInterval"), 5 * 60 * 1000) - ); } onunload() {} @@ -88,9 +84,9 @@ export default class MyPlugin extends Plugin { const res = await upload.syncMarkdownToNotion(basename,fileData, fullPath) console.log(res) if(res.status === 200){ - new Notice(`${basename}同步成功`) + new Notice(`${basename} 同步成功`) }else { - new Notice(`${basename}同步失败`) + new Notice(`${basename} 同步失败`) } } }