Skip to content

Commit

Permalink
feat: 图床直接调用挂件
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 16, 2023
1 parent 1d98fd6 commit ba57fe3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[中文](README_zh_CN.md)

# Publish Tool
# Publisher

![](https://raw.githubusercontent.com/terwer/siyuan-plugin-publisher/main/plugins/publisher-main/public/icon.png)

Expand Down
2 changes: 1 addition & 1 deletion libs/publisher-bridge/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import minimist from "minimist"

const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w
const devDistDir = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/publish-tool/lib/bridge"
const devDistDir = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/siyuan-publisher/lib/bridge"
const distDir = isWatch ? devDistDir : "./dist"

export default defineConfig({
Expand Down
6 changes: 3 additions & 3 deletions plugins/publisher-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"svelte-routing": "^1.8.8"
},
"dependencies": {
"zhi-blog-api": "^1.1.0",
"zhi-publisher-sdk": "^0.0.1",
"zhi-siyuan-api": "^1.1.1"
"zhi-blog-api": "/Users/terwer/Documents/mydocs/zhi-framework/zhi/libs/zhi-blog-api",
"zhi-siyuan-api": "/Users/terwer/Documents/mydocs/zhi-framework/zhi/libs/zhi-siyuan-api",
"zhi-publisher-sdk": "/Users/terwer/Documents/mydocs/zhi-framework/zhi/libs/zhi-publisher-sdk"
}
}
2 changes: 1 addition & 1 deletion plugins/publisher-main/public/i18n/en_US.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"publishTool": "Publish Tool",
"publishTool": "Publisher",
"publish": "Publish",
"picbed": "Upload picture to picbed",
"setting": "Setting",
Expand Down
6 changes: 3 additions & 3 deletions plugins/publisher-main/public/plugin.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "publish-tool",
"name": "siyuan-publisher",
"author": "terwer",
"url": "https://github.com/terwer/siyuan-plugin-publisher",
"version": "0.8.0",
"displayName": {
"default": "Publish Tool",
"default": "Publisher",
"zh_CN": "发布工具"
},
"description": {
Expand All @@ -21,7 +21,7 @@
],
"funding": {
"custom": [
"https://afdian.net/a/terwer"
"https://img1.terwer.space/api/public/202305170050348.jpg"
]
}
}
62 changes: 39 additions & 23 deletions plugins/publisher-main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const STORAGE_NAME = "menu-config"
// https://github.com/siyuan-note/siyuan/pull/8188/
// https://github.com/vitejs/vite/issues/6582#issuecomment-1546954468
// https://github.com/sveltejs/svelte-preprocess/issues/91#issuecomment-548527600
export default class PublishTool extends Plugin {
export default class PublishToolPlugin extends Plugin {
private env: Env = new Env(process.env)
private logger: DefaultLogger = new CustomLogFactory(undefined, "publish-tool", this.env).getLogger("main")

Expand All @@ -25,11 +25,11 @@ export default class PublishTool extends Plugin {
// lifecycle
public onload() {
this._addTopBar()
this.logger.debug(`Publish Tool loaded ${new Date().getTime()}`)
this.logger.debug(`Publisher loaded at 1111 ${new Date().getTime()}`)
}

public onunload() {
this.logger.debug("Publish Tool unloaded")
this.logger.debug("Publisher unloaded")
}

public openSetting() {
Expand Down Expand Up @@ -204,14 +204,15 @@ export default class PublishTool extends Plugin {
}

private _showPicbedDialog() {
new Dialog({
title: `${this.i18n.picbed} - ${this.i18n.publishTool}`,
content: `<div id="${PageUtil.getElementId(Constants.Page.Picbed)}"></div>`,
width: isMobile() ? "92vw" : "520px",
})
// new Dialog({
// title: `${this.i18n.picbed} - ${this.i18n.publishTool}`,
// content: `<div id="${PageUtil.getElementId(Constants.Page.Picbed)}"></div>`,
// width: isMobile() ? "92vw" : "520px",
// })

// setting
PageUtil.createApp(Constants.Page.Picbed)
// PageUtil.createApp(Constants.Page.Picbed)
this._showPublisherWidget("picgo")
}

private _showSettingDialog() {
Expand Down Expand Up @@ -244,34 +245,49 @@ export default class PublishTool extends Plugin {
} as any)
}

private _showPublisherWidget() {
private _showPublisherWidget(type?: "blog" | "detail" | "picgo") {
const win = window as any
const deviceType: DeviceTypeEnum = DeviceDetection.getDevice()
this.logger.info(`you are from ${deviceType}`)

const publisherIndex = `/widgets/sy-post-publisher/index.html`
let pageId: string | undefined = PageUtil.getPageId()
if (pageId == "") {
pageId = undefined
}
this.logger.debug("pageId=>", pageId)

if (deviceType == DeviceTypeEnum.DeviceType_Siyuan_MainWin) {
import("/plugins/publish-tool/lib/bridge/index.js" as any).then((bridge) => {
import("/plugins/siyuan-publisher/lib/bridge/index.js" as any).then((bridge) => {
const publisherBridge = new bridge.default()
publisherBridge.init().then(() => {
// 发布首页
const pageId = PageUtil.getPageId()
const pageUrl = "index.html"

// 博客首页
// const pageId: any = undefined
// const pageUrl = "blog/index.html"

// 详情
// const pageId = PageUtil.getPageId()
// const pageUrl = "detail/index.html"
let pageUrl
switch (type) {
case "blog":
// 博客首页
pageUrl = "blog/index.html"
break
case "detail":
// 详情
pageUrl = "detail/index.html"
break
case "picgo":
pageUrl = "picgo/index.html"
break
default:
// 发布首页
pageUrl = "index.html"
break
}
if (!pageId && pageUrl === "index.html") {
pageUrl = "blog/index.html"
}

win.syp.renderPublishHelper(pageId, pageUrl, win, this.env.isDev())
this.logger.debug("publisherHook inited")
})
})
} else {
const publisherIndex = `/widgets/sy-post-publisher/index.html`
this._showPublisherDialog(publisherIndex)
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/publisher-main/src/utils/pageUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PageUtil {
}

public static getElementId(pageId: string) {
return pageId === "" ? "home" : `publish-tool-${pageId}`
return pageId === "" ? "home" : `siyuan-publisher-${pageId}`
}

public static createApp(pageId: string): App {
Expand Down
4 changes: 2 additions & 2 deletions plugins/publisher-main/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { svelte } from "@sveltejs/vite-plugin-svelte"

const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w
const devDistDir = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/publish-tool"
const devDistDir = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/siyuan-publisher"
const distDir = isWatch ? devDistDir : "./dist"
// const mode = process.env.NODE_ENV
const mode = isWatch ? "development" : "production"
Expand Down Expand Up @@ -101,7 +101,7 @@ export default defineConfig({

// make sure to externalize deps that shouldn't be bundled
// into your library
external: ["siyuan", "process", "/plugins/publish-tool/lib/bridge/index.js"],
external: ["siyuan", "process", "/plugins/siyuan-publisher/lib/bridge/index.js"],

output: {
chunkFileNames: "static/js/[name]-[hash].js",
Expand Down

0 comments on commit ba57fe3

Please sign in to comment.