Skip to content

Commit

Permalink
feat: 发布工具插件版第一版-调整菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jun 24, 2023
1 parent 4fc2d56 commit 10df790
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 37 deletions.
11 changes: 11 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
"author": "terwer",
"url": "https://github.com/terwer/siyuan-plugin-publisher",
"version": "0.0.1",
"minAppVersion": "2.9.0",
"backends": [
"windows",
"linux",
"darwin",
"docker"
],
"frontends": [
"desktop",
"desktop-window"
],
"displayName": {
"default": "Publisher",
"zh_CN": "发布工具"
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"settingGeneral": "General setting",
"settingPicbed": "Picbed manage",
"settingPublish": "Publish setting",
"settingPlatform": "Platform setting",
"settingMenuTips": "Let creation return to fun",
"copyPageId": "Copy pageId",
"publisherWidget": "Publisher Widget",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"settingGeneral": "偏好设置",
"settingPicbed": "图床设置",
"settingPublish": "发布设置",
"settingPlatform": "平台设置",
"settingMenuTips": "让创作回归乐趣",
"copyPageId": "复制文档ID",
"publisherWidget": "挂件版",
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@
*/

import { App, IObject, Plugin, getFrontend } from "siyuan"
import { SiyuanConfig, SiyuanKernelApi } from "zhi-siyuan-api"
import { createAppLogger } from "./appLogger"
import { WidgetInvoke } from "./invoke/widgetInvoke"
import { Topbar } from "./topbar"

import "../index.styl"
import { SiyuanConfig, SiyuanKernelApi } from "zhi-siyuan-api"

export default class PublisherPlugin extends Plugin {
private logger
private topbar

public isMobile: boolean
public kernelApi: SiyuanKernelApi
private widgetInvoke

constructor(options: { app: App; id: string; name: string; i18n: IObject }) {
super(options)
Expand All @@ -49,6 +51,11 @@ export default class PublisherPlugin extends Plugin {
this.kernelApi = new SiyuanKernelApi(siyuanConfig)

this.topbar = new Topbar(this)
this.widgetInvoke = new WidgetInvoke(this)
}

openSetting(): void {
this.widgetInvoke.showPublisherSettingDialog()
}

onload() {
Expand Down
52 changes: 23 additions & 29 deletions src/invoke/widgetInvoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,27 @@ export class WidgetInvoke {
this.pluginInstance = pluginInstance
}

public showPublisherWidget(type?: "blog") {
public showPublisherPublishDialog() {
this.showPage("/")
}

public showPublisherSettingDialog() {
this.showPage("/setting")
}

public showPublisherGeneralSettingDialog() {
this.showPage("/setting/general")
}

public showPublisherPublishSettingDialog() {
this.showPage("/setting/publish")
}

public showPublisherPlatformSettingDialog() {
this.showPage("/setting/platform")
}

private showPage(pageUrl) {
const win = window as any
const deviceType: DeviceTypeEnum = DeviceDetection.getDevice()
this.logger.info(`you are from ${deviceType}`)
Expand All @@ -53,33 +73,7 @@ export class WidgetInvoke {
}
this.logger.debug("pageId=>", pageId)

if (deviceType == DeviceTypeEnum.DeviceType_Siyuan_MainWin) {
const libBase = "/plugins/siyuan-publisher/"
import(`${libBase}/libs/plugin-publisher-bridge/index.js` as any).then((bridge) => {
const publisherBridge = new bridge.default()
publisherBridge.init().then(() => {
let pageUrl
switch (type) {
case "blog":
// 博客首页
pageUrl = "blog/index.html"
break
default:
// 发布首页
pageUrl = "index.html"
break
}
if (!pageId && pageUrl === "index.html") {
pageUrl = "blog/index.html"
}

win.syp.renderPublishHelper(pageId, pageUrl, win, isDev)
this.logger.debug("publisherHook inited")
})
})
} else {
const publisherIndex = `/widgets/sy-post-publisher/index.html`
showIframeDialog(this.pluginInstance, publisherIndex)
}
const url = `/widgets/sy-post-publisher/#${pageUrl}`
showIframeDialog(this.pluginInstance, url)
}
}
26 changes: 19 additions & 7 deletions src/topbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class Topbar {
iconHTML: icons.iconPen,
label: this.pluginInstance.i18n.publishNormal,
click: () => {
this.widgetInvoke.showPublisherWidget("blog")
this.widgetInvoke.showPublisherPublishDialog()
},
})

Expand Down Expand Up @@ -162,13 +162,22 @@ export class Topbar {
icon: "iconSettings",
label: this.pluginInstance.i18n.setting,
click: () => {
// this.showSettingDialog()
this.widgetInvoke.showPublisherSettingDialog()
},
submenu: [
{
iconHTML: icons.iconPreference,
label: this.pluginInstance.i18n.settingGeneral,
click: () => {},
iconHTML: icons.iconPublish,
label: this.pluginInstance.i18n.settingPublish,
click: () => {
this.widgetInvoke.showPublisherPublishSettingDialog()
},
},
{
iconHTML: icons.iconPlatform,
label: this.pluginInstance.i18n.settingPlatform,
click: () => {
this.widgetInvoke.showPublisherPlatformSettingDialog()
},
},
{
iconHTML: icons.iconPicbed,
Expand All @@ -178,8 +187,11 @@ export class Topbar {
},
},
{
iconHTML: icons.iconPublish,
label: this.pluginInstance.i18n.settingPublish,
iconHTML: icons.iconPreference,
label: this.pluginInstance.i18n.settingGeneral,
click: () => {
this.widgetInvoke.showPublisherGeneralSettingDialog()
},
},
],
})
Expand Down
1 change: 1 addition & 0 deletions src/utils/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const icons = {
iconPicture: `<span class="iconfont-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M0 96C0 60.7 28.7 32 64 32H448c35.3 0 64 28.7 64 64V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96zM323.8 202.5c-4.5-6.6-11.9-10.5-19.8-10.5s-15.4 3.9-19.8 10.5l-87 127.6L170.7 297c-4.6-5.7-11.5-9-18.7-9s-14.2 3.3-18.7 9l-64 80c-5.8 7.2-6.9 17.1-2.9 25.4s12.4 13.6 21.6 13.6h96 32H424c8.9 0 17.1-4.9 21.2-12.8s3.6-17.4-1.4-24.7l-120-176zM112 192a48 48 0 1 0 0-96 48 48 0 1 0 0 96z"/></svg></span>`,
iconOl: `<span class="iconfont-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M24 56c0-13.3 10.7-24 24-24H80c13.3 0 24 10.7 24 24V176h16c13.3 0 24 10.7 24 24s-10.7 24-24 24H40c-13.3 0-24-10.7-24-24s10.7-24 24-24H56V80H48C34.7 80 24 69.3 24 56zM86.7 341.2c-6.5-7.4-18.3-6.9-24 1.2L51.5 357.9c-7.7 10.8-22.7 13.3-33.5 5.6s-13.3-22.7-5.6-33.5l11.1-15.6c23.7-33.2 72.3-35.6 99.2-4.9c21.3 24.4 20.8 60.9-1.1 84.7L86.8 432H120c13.3 0 24 10.7 24 24s-10.7 24-24 24H32c-9.5 0-18.2-5.6-22-14.4s-2.1-18.9 4.3-25.9l72-78c5.3-5.8 5.4-14.6 .3-20.5zM224 64H480c17.7 0 32 14.3 32 32s-14.3 32-32 32H224c-17.7 0-32-14.3-32-32s14.3-32 32-32zm0 160H480c17.7 0 32 14.3 32 32s-14.3 32-32 32H224c-17.7 0-32-14.3-32-32s14.3-32 32-32zm0 160H480c17.7 0 32 14.3 32 32s-14.3 32-32 32H224c-17.7 0-32-14.3-32-32s14.3-32 32-32z"/></svg></span>`,
iconPreference: `<span class="iconfont-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M352 320c88.4 0 160-71.6 160-160c0-15.3-2.2-30.1-6.2-44.2c-3.1-10.8-16.4-13.2-24.3-5.3l-76.8 76.8c-3 3-7.1 4.7-11.3 4.7H336c-8.8 0-16-7.2-16-16V118.6c0-4.2 1.7-8.3 4.7-11.3l76.8-76.8c7.9-7.9 5.4-21.2-5.3-24.3C382.1 2.2 367.3 0 352 0C263.6 0 192 71.6 192 160c0 19.1 3.4 37.5 9.5 54.5L19.9 396.1C7.2 408.8 0 426.1 0 444.1C0 481.6 30.4 512 67.9 512c18 0 35.3-7.2 48-19.9L297.5 310.5c17 6.2 35.4 9.5 54.5 9.5zM80 408a24 24 0 1 1 0 48 24 24 0 1 1 0-48z"/></svg></span>`,
iconPlatform: `<span class="iconfont-icon"><svg t="1687610705464" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3108" width="13" height="13"><path d="M446.464 839.68v-65.536h131.072v65.536h196.608v65.536H249.856v-65.536h196.608zM118.784 708.608V118.784h786.432v589.824H118.784z" p-id="3109"></path></svg></span>`,
iconPicbed: `<span class="iconfont-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M160 32c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64H512c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H160zM396 138.7l96 144c4.9 7.4 5.4 16.8 1.2 24.6S480.9 320 472 320H328 280 200c-9.2 0-17.6-5.3-21.6-13.6s-2.9-18.2 2.9-25.4l64-80c4.6-5.7 11.4-9 18.7-9s14.2 3.3 18.7 9l17.3 21.6 56-84C360.5 132 368 128 376 128s15.5 4 20 10.7zM192 128a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zM48 120c0-13.3-10.7-24-24-24S0 106.7 0 120V344c0 75.1 60.9 136 136 136H456c13.3 0 24-10.7 24-24s-10.7-24-24-24H136c-48.6 0-88-39.4-88-88V120z"/></svg></span>`,
iconPublish: `<span class="iconfont-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M352 224H305.5c-45 0-81.5 36.5-81.5 81.5c0 22.3 10.3 34.3 19.2 40.5c6.8 4.7 12.8 12 12.8 20.3c0 9.8-8 17.8-17.8 17.8h-2.5c-2.4 0-4.8-.4-7.1-1.4C210.8 374.8 128 333.4 128 240c0-79.5 64.5-144 144-144h80V34.7C352 15.5 367.5 0 386.7 0c8.6 0 16.8 3.2 23.2 8.9L548.1 133.3c7.6 6.8 11.9 16.5 11.9 26.7s-4.3 19.9-11.9 26.7l-139 125.1c-5.9 5.3-13.5 8.2-21.4 8.2H384c-17.7 0-32-14.3-32-32V224zM80 96c-8.8 0-16 7.2-16 16V432c0 8.8 7.2 16 16 16H400c8.8 0 16-7.2 16-16V384c0-17.7 14.3-32 32-32s32 14.3 32 32v48c0 44.2-35.8 80-80 80H80c-44.2 0-80-35.8-80-80V112C0 67.8 35.8 32 80 32h48c17.7 0 32 14.3 32 32s-14.3 32-32 32H80z"/></svg></span>`,
iconCnblogs: `<span class="iconfont-icon"><svg t="1684168925817" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4454" width="16" height="16"><path d="M851.404 172.596c-187.462-187.461-491.346-187.461-678.808 0-187.461 187.462-187.461 491.346 0 678.808 187.462 187.461 491.346 187.461 678.808 0 187.461-187.462 187.461-491.346 0-678.808zM387.33 728.087a47.084 47.084 0 1 1-66.633-66.502 47.084 47.084 0 0 1 66.633 66.502z m205.527 1.397a38.75 38.75 0 0 1-76.625-11.52h-0.044a6.545 6.545 0 0 0-0.044 0.305v-0.349c0.306-2.618 2.051-20.727-2.967-44.99a174.24 174.24 0 0 0-48.567-89.28 172.102 172.102 0 0 0-88.8-48.305 156.698 156.698 0 0 0-42.458-2.923 38.662 38.662 0 0 1-35.39-65.324 38.618 38.618 0 0 1 21.12-10.822v-0.218c4.452-0.742 111.142-16.45 200.335 72.742 89.018 89.018 74.182 196.145 73.44 200.727z m175.2 7.592a38.75 38.75 0 0 1-65.673 21.382 39.49 39.49 0 0 1-11.65-33.73c0.087-0.35 5.105-37.484-5.062-88.975-13.31-67.375-45.295-126.895-94.953-176.902-50.007-49.702-109.527-81.644-176.945-94.953-51.491-10.167-88.582-5.193-89.019-5.149h0.219-0.044a39.927 39.927 0 0 1-44.684-32.902 38.836 38.836 0 0 1 32.204-44.378c1.92-0.305 47.869-7.33 111.273 4.364a411.753 411.753 0 0 1 106.254 34.952 425.76 425.76 0 0 1 114.633 82.255l0.916 0.96 0.96 0.873a425.89 425.89 0 0 1 82.255 114.72c16.407 33.6 28.145 69.294 34.996 106.21 11.651 63.404 4.67 109.353 4.32 111.273z" fill="#bfbfbf" p-id="4455"></path></svg></span>`,
Expand Down

0 comments on commit 10df790

Please sign in to comment.