Skip to content

Commit

Permalink
feat: 新增 publisher-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jun 23, 2023
1 parent e926ac7 commit c8192cf
Show file tree
Hide file tree
Showing 13 changed files with 3,763 additions and 228 deletions.
12 changes: 0 additions & 12 deletions apps/publisher-main/index.html

This file was deleted.

20 changes: 11 additions & 9 deletions apps/publisher-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,28 @@
"package": "python scripts/package.py"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.4.1",
"@terwer/eslint-config-custom": "^1.3.4",
"@sveltejs/vite-plugin-svelte": "^2.4.2",
"@terwer/eslint-config-custom": "^1.3.6",
"@tsconfig/svelte": "^4.0.1",
"@types/minimist": "1.2.2",
"fast-glob": "^3.2.12",
"jsdom": "^22.0.0",
"jsdom": "^22.1.0",
"minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5",
"siyuan": "^0.7.2",
"siyuan": "^0.7.4",
"stylus": "^0.59.0",
"svelte": "^3.59.1",
"typescript": "^5.0.4",
"vite": "^4.3.5",
"svelte": "^3.59.2",
"typescript": "^5.1.3",
"vite": "^4.3.9",
"vite-plugin-dts": "^2.3.0",
"vite-plugin-node-polyfills": "^0.8.2",
"vite-plugin-static-copy": "^0.16.0",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.32.0"
"vitest": "^0.32.2"
},
"dependencies": {
"zhi-lib-base": "^0.2.4"
"zhi-device": "^2.3.0",
"zhi-lib-base": "^0.2.6",
"zhi-siyuan-api": "^1.23.0"
}
}
21 changes: 21 additions & 0 deletions apps/publisher-main/src/i18n/en_US.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
{
"publishTool": "Publisher",
"publish": "Publish",
"picbed": "Upload picture to picbed",
"setting": "Setting",
"settingGeneral": "General setting",
"settingPicbed": "Picbed manage",
"settingPublish": "Publish setting",
"settingMenuTips": "Let creation return to fun",
"copyPageId": "Copy pageId",
"publisherWidget": "Publisher Widget",
"cancel": "Cancel",
"save": "Save",
"publishTo": "Publish to...",
"platformCnblogs": "Cnblogs",
"platformTypecho": "Typecho",
"platformWordpress": "WordPress",
"platformYuque": "Yuque",
"platformGithub": "Github",
"platformHexo": "Hexo",
"platformHugo": "Hugo",
"platformVitepress": "Vitepress"
}
21 changes: 21 additions & 0 deletions apps/publisher-main/src/i18n/zh_CN.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
{
"publishTool": "发布工具",
"publish": "发布",
"picbed": "上传图片到图床",
"setting": "设置",
"settingGeneral": "偏好设置",
"settingPicbed": "图床管理",
"settingPublish": "发布设置",
"settingMenuTips": "让创作回归乐趣",
"copyPageId": "复制文档ID",
"publisherWidget": "挂件版",
"cancel": "取消",
"save": "保存",
"publishTo": "发布到...",
"platformCnblogs": "博客园",
"platformTypecho": "Typecho",
"platformWordpress": "WordPress",
"platformYuque": "语雀",
"platformGithub": "Github",
"platformHexo": "Hexo",
"platformHugo": "Hugo",
"platformVitepress": "Vitepress"
}
52 changes: 52 additions & 0 deletions apps/publisher-main/src/iframeDialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

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

/**
* 打开 iframe 弹窗
*
* @param pluginInstance 插件实例
* @param pageIndex 地址
*/
export const showIframeDialog = (pluginInstance: PublisherPlugin, pageIndex: string) => {
const contentHtml = `<style>
iframe {
width: 100%;
height: 100%;
border: none;
}
</style>
<iframe src="${pageIndex}" width="100%"></iframe>`

new Dialog({
title: pluginInstance.i18n.siyuanBlog,
transparent: false,
content: contentHtml,
width: "90%",
height: "750px",
} as any)
}
22 changes: 15 additions & 7 deletions apps/publisher-main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,33 @@
* questions.
*/

import { App, IObject, Plugin } from "siyuan"
import { App, IObject, Plugin, getFrontend } from "siyuan"
import { createAppLogger } from "./appLogger"
import { Topbar } from "./topbar"

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

export default class PublisherPlugin extends Plugin {
private logger
private topbar

public isMobile: boolean
public kernelApi: SiyuanKernelApi

constructor(options: { app: App; id: string; name: string; i18n: IObject }) {
super(options)

this.logger = createAppLogger("index")
}
const frontEnd = getFrontend()
this.isMobile = frontEnd === "mobile" || frontEnd === "browser-mobile"
const siyuanConfig = new SiyuanConfig("", "")
this.kernelApi = new SiyuanKernelApi(siyuanConfig)

onload() {
this.logger.info("Publisher loaded")
this.topbar = new Topbar(this)
}

onunload() {
this.logger.info("Publisher unloaded")
onload() {
this.topbar.initTopbar()
}
}
Loading

0 comments on commit c8192cf

Please sign in to comment.