Skip to content

Commit

Permalink
refactor: 新增按钮菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 20, 2023
1 parent ee2e562 commit 664ac12
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 3 deletions.
Binary file added public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
155 changes: 153 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Plugin } from "siyuan"
import { isMobile, Menu, Plugin } from "siyuan"
import "./index.styl"
import { initLibs } from "~/src/loader"
import { initTools } from "~/src/tools"
import iconPublish from "~/src/utils/svg"
import { Utils } from "~/src/utils/utils";

export default class PublisherPlugin extends Plugin {
public fs
Expand Down Expand Up @@ -59,7 +61,7 @@ export default class PublisherPlugin extends Plugin {
this.logger.info("siyuan recent post=>", posts)

// 初始化菜单按钮
// TODO
this.initTopBar()

this.logger.info(this.i18n.publisherLoaded)
}
Expand All @@ -71,4 +73,153 @@ export default class PublisherPlugin extends Plugin {
// ======================
// private functions
// ======================
private initTopBar() {
const topBarElement = this.addTopBar({
icon: iconPublish.iconPlane,
title: this.i18n.publisher,
position: "left",
callback: () => {
this.initMenu(topBarElement.getBoundingClientRect())
},
})
}

private async initMenu(rect: DOMRect) {
const menu = new Menu("topBarSample")

// 发布到
menu.addItem({
icon: `iconRiffCard`,
label: this.i18n.publishTo,
submenu: [
{
iconHTML: iconPublish.iconCnblogs,
label: this.i18n.platformCnblogs,
click: async () => {
// const blogApi = PublishSdk.blogApi(BlogTypeEnum.BlogTypeEnum_Metaweblog)
// const usersBlogs = blogApi.getUsersBlogs()
const blogApi = Utils.blogApi(this)
// const usersBlogs = await blogApi.getUsersBlogs()
// this.logger.info("发布到博客园", usersBlogs)
const recentPosts = await blogApi.getRecentPosts(10)
this.logger.info("发布到博客园", recentPosts)
},
},
{
iconHTML: iconPublish.iconTypecho,
label: this.i18n.platformTypecho,
disabled: true,
click: () => {
this.logger.debug("发布到Typecho")
},
},
{
iconHTML: iconPublish.iconWordpress,
label: this.i18n.platformWordpress,
click: () => {
this.logger.debug("发布到WordPress")
},
},
{
iconHTML: iconPublish.iconYuque,
label: this.i18n.platformYuque,
click: () => {
this.logger.debug("发布到语雀")
},
},
{
iconHTML: iconPublish.iconGithub,
label: this.i18n.platformGithub,
submenu: [
{
iconHTML: iconPublish.iconHexo,
label: this.i18n.platformHexo,
click: () => {
this.logger.debug("发布到Hexo")
},
},
{
iconHTML: iconPublish.iconHugo,
label: this.i18n.platformHugo,
click: () => {
this.logger.debug("发布到Hugo")
},
},
{
iconHTML: iconPublish.iconVue,
label: this.i18n.platformVitepress,
click: () => {
this.logger.debug("发布到Vitepress")
},
},
],
},
],
})

// 图床
menu.addSeparator()
menu.addItem({
iconHTML: iconPublish.iconPicture,
label: this.i18n.picbed,
// click: () => {},
})

// 设置
menu.addSeparator()
menu.addItem({
icon: "iconSettings",
label: this.i18n.setting,
// click: () => {},
submenu: [
{
iconHTML: iconPublish.iconPreference,
label: this.i18n.settingGeneral,
// click: () => {},
},
{
iconHTML: iconPublish.iconPicbed,
label: this.i18n.settingPicbed,
},
{
iconHTML: iconPublish.iconPublish,
label: this.i18n.settingPublish,
},
],
})

// 当前文档ID
// const pageId = PageUtil.getPageId()
menu.addSeparator()
menu.addItem({
iconHTML: iconPublish.iconOl,
label: this.i18n.copyPageId,
click: async () => {
// await HtmlUtils.copyToClipboard(pageId)
// this.kernelApi.pushMsg({
// msg: `当前文档ID已复制=>${pageId}`,
// timeout: 3000,
// })
// this.logger.info("当前文档ID已复制", pageId)
},
})

// slogan
menu.addSeparator()
menu.addItem({
icon: "iconSparkles",
label: this.i18n.settingMenuTips,
type: "readonly",
})

if (isMobile()) {
menu.fullscreen()
} else {
menu.open({
x: rect.right,
y: rect.bottom,
isLeft: true,
})
}
}
}
2 changes: 1 addition & 1 deletion src/siyuan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ declare module "siyuan" {
sid: string
}

declare interface IPluginDockTab {
interface IPluginDockTab {
position: "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight",
size: { width: number, height: number },
icon: string,
Expand Down
Loading

0 comments on commit 664ac12

Please sign in to comment.