Skip to content

Commit

Permalink
feat: 发布工具插件版第一版-支持发布预览
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jun 23, 2023
1 parent 21e3afd commit 4fc2d56
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/iframeDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@
* questions.
*/

import { Dialog } from "siyuan"
import { Dialog, IObject } from "siyuan"
import PublisherPlugin from "./index"

/**
* 打开 iframe 弹窗
*
* @param pluginInstance 插件实例
* @param pageIndex 地址
* @param destroyCallback 关闭回调
*/
export const showIframeDialog = (pluginInstance: PublisherPlugin, pageIndex: string) => {
export const showIframeDialog = (
pluginInstance: PublisherPlugin,
pageIndex: string,
destroyCallback?: (options?: IObject) => void
) => {
const contentHtml = `<style>
iframe {
width: 100%;
Expand All @@ -46,7 +51,8 @@ export const showIframeDialog = (pluginInstance: PublisherPlugin, pageIndex: str
title: pluginInstance.i18n.siyuanBlog,
transparent: false,
content: contentHtml,
width: "90%",
height: "750px",
width: "60%",
height: "650px",
destroyCallback: destroyCallback,
} as any)
}
27 changes: 25 additions & 2 deletions src/invoke/pluginInvoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import PublisherPlugin from "../index"
import { createAppLogger } from "../appLogger"
import { showIframeDialog } from "../iframeDialog"
import PageUtil from "../utils/pageUtil"
import { IObject } from "siyuan"

/**
* 插件相关
Expand All @@ -43,11 +44,33 @@ export class PluginInvoke {
}

public async showBlogDialog() {
const pageId: string | undefined = PageUtil.getPageId()

// 检测是否安装博客插件
await this.preCheckPicgoPlugin()

const pageId: string | undefined = PageUtil.getPageId()
// 临时开启预览权限
let isShared = false
const attrs = await this.pluginInstance.kernelApi.getBlockAttrs(pageId)
if (attrs["custom-publish-status"] === "publish") {
isShared = true
} else {
await this.pluginInstance.kernelApi.setBlockAttrs(pageId, {
"custom-publish-status": "preview",
})
this.logger.info("The document is not shared, will temporarily turn on preview permissions")
}

const pageUrl = `${this.blogPluginBase}/post/${pageId}`
showIframeDialog(this.pluginInstance, pageUrl)
showIframeDialog(this.pluginInstance, pageUrl, async (options?: IObject) => {
// 回收预览权限
if (!isShared) {
await this.pluginInstance.kernelApi.setBlockAttrs(pageId, {
"custom-publish-status": "draft",
})
this.logger.info("Temporary permissions are turned off")
}
})
}

public async showPicbedDialog() {
Expand Down

0 comments on commit 4fc2d56

Please sign in to comment.