From 4a01605dc3db0c038f4a6579f4f67ccf3325a1e1 Mon Sep 17 00:00:00 2001 From: Jay Nguyen Date: Sun, 10 Apr 2022 17:11:28 +0100 Subject: [PATCH] minor change --- src/methods/publishPost.ts | 10 +++++----- src/types/index.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/methods/publishPost.ts b/src/methods/publishPost.ts index 144e5b8..8658956 100644 --- a/src/methods/publishPost.ts +++ b/src/methods/publishPost.ts @@ -1,3 +1,4 @@ +import { SettingsProp, ViewProp, ContentProp } from './../types/index'; import { Notice, request } from "obsidian"; import { sign } from 'jsonwebtoken'; @@ -5,7 +6,7 @@ const MarkdownIt = require("markdown-it") const md = new MarkdownIt() -export const publishPost = async (view: any, settings: any) => { +export const publishPost = async (view: ViewProp, settings: SettingsProp) => { const content = { title: view.file.basename, @@ -32,7 +33,7 @@ export const publishPost = async (view: any, settings: any) => { }); - const contentPost = (content: any, settings: any) => ({ + const contentPost = (content: ContentProp, settings: SettingsProp) => ({ "posts": [{ "title": content.title, "html": md.render(content.data), @@ -56,7 +57,6 @@ export const publishPost = async (view: any, settings: any) => { body: JSON.stringify(body) }) - const json = JSON.parse(result) if (json?.errors) { @@ -64,8 +64,8 @@ export const publishPost = async (view: any, settings: any) => { } if (json?.posts) { - new Notice(`${json.posts[0].settings.title} has been ${json.posts[0].settings.status} successful!`) + new Notice(`"${json?.posts?.[0]?.title}" has been ${json?.posts?.[0]?.status} successful!`) } - return result + return json } \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index ca7fae8..3dd6d09 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -10,3 +10,15 @@ export const DEFAULT_SETTINGS: SettingsProp = { publishStatus: 'draft' } + +export interface ViewProp { + file: { + basename: string + }, + data: string +} + +export interface ContentProp { + title: string, + data: string +}