Skip to content

Commit

Permalink
feat: 新增发布菜单、页面路由
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 15, 2023
1 parent c771f12 commit 70bc06b
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 295 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ jobs:
run: pnpm build

- name: Package
run: pnpm package
# 上面的 Build 已经构建过了,这里可以忽略 Build ,避免重复运行
run: pnpm package -s
4 changes: 3 additions & 1 deletion plugins/publisher-main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"@terwer/vite-config-custom": "^0.4.0",
"@tsconfig/svelte": "^4.0.1",
"siyuan": "^0.7.1",
"svelte": "^3.57.0"
"stylus": "^0.59.0",
"svelte": "^3.57.0",
"svelte-routing": "^1.8.8"
},
"dependencies": {
"zhi-device": "^0.5.0",
Expand Down
4 changes: 3 additions & 1 deletion plugins/publisher-main/public/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"settingMenuTips": "Let creation return to fun",
"publisherWidget": "Publisher Widget",
"cancel": "Cancel",
"save": "Save"
"save": "Save",
"publishTo": "Publish to...",
"platformCnblogs": "Cnblogs"
}
4 changes: 3 additions & 1 deletion plugins/publisher-main/public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"settingMenuTips": "让创作回归乐趣",
"publisherWidget": "挂件版",
"cancel": "取消",
"save": "保存"
"save": "保存",
"publishTo": "发布到...",
"platformCnblogs": "博客园"
}
52 changes: 34 additions & 18 deletions plugins/publisher-main/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
<!--
- 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.
-->

<script lang="ts">
import Counter from "./lib/Counter.svelte"
const message = "Hello, World!"
import { Route, Router } from "svelte-routing"
import Preferences from "./routes/Preferences.svelte"
import Publish from "./routes/Publish.svelte"
export let url = "/"
</script>

<main>
<Router {url}>
<div>
This is svelte {message}
<Counter />

<!--
<div class="b3-dialog__content">
<textarea class="b3-text-field fn__block" placeholder="readonly text in the menu" />
</div>
<div class="b3-dialog__action">
<button class="b3-button b3-button--cancel">${this.i18n.cancel}</button>
<div class="fn__space" />
<button class="b3-button b3-button--text">${this.i18n.save}</button>
</div>
</div>
-->
<Route path="/setting" component={Preferences} />
<Route path="/" component={Publish} />
</div>
</main>
</Router>
31 changes: 31 additions & 0 deletions plugins/publisher-main/src/index.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

// 图标
.pt-icon{
width 12px
height 12px
margin-right 8px
}
51 changes: 37 additions & 14 deletions plugins/publisher-main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import App from "./App.svelte"
import { DeviceDetection, DeviceTypeEnum } from "zhi-device"
import { Env } from "zhi-env"
import { CustomLogFactory, DefaultLogger } from "zhi-log"
import "./index.styl"

const STORAGE_NAME = "menu-config"
const SETTING_CONTAINER = "publish-tool-setting"

// 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 {
private env: Env = new Env(process.env)
Expand Down Expand Up @@ -44,6 +46,23 @@ export default class PublishTool extends Plugin {
}

const menu = new Menu("topBarSample")
// 发布到
menu.addItem({
icon: `iconRiffCard`,
label: this.i18n.publishTo,
submenu: [
{
iconHTML: `<span class="pt-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M0 64C0 46.3 14.3 32 32 32c229.8 0 416 186.2 416 416c0 17.7-14.3 32-32 32s-32-14.3-32-32C384 253.6 226.4 96 32 96C14.3 96 0 81.7 0 64zM0 416a64 64 0 1 1 128 0A64 64 0 1 1 0 416zM32 160c159.1 0 288 128.9 288 288c0 17.7-14.3 32-32 32s-32-14.3-32-32c0-123.7-100.3-224-224-224c-17.7 0-32-14.3-32-32s14.3-32 32-32z"/></svg></span>`,
label: this.i18n.platformCnblogs,
click: () => {
this.logger.debug("发布到博客园")
},
},
],
})

// 设置
menu.addSeparator()
menu.addItem({
icon: "iconSettings",
label: this.i18n.setting,
Expand All @@ -52,6 +71,7 @@ export default class PublishTool extends Plugin {
},
})

// 挂件版
menu.addSeparator()
menu.addItem({
icon: "iconTransform",
Expand All @@ -61,12 +81,26 @@ export default class PublishTool extends Plugin {
},
})

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

// 调试阶段显示当前文档ID
if (this.env.isDev()) {
const pageId = "112123e343242-2323"
menu.addSeparator()
menu.addItem({
label: pageId,
type: "readonly",
click: () => {
this.logger.debug("当前文档ID已复制", pageId)
},
})
}
if (isMobile()) {
menu.fullscreen()
} else {
Expand All @@ -88,21 +122,10 @@ export default class PublishTool extends Plugin {
// setting
new App({
target: document.getElementById(SETTING_CONTAINER) as HTMLElement,
props: {
url: "/setting",
},
})

// const inputElement = dialog.element.querySelector("textarea") as HTMLTextAreaElement
// const btnsElement = dialog.element.querySelectorAll(".b3-button")
// dialog.bindInput(inputElement, () => {
// ;(btnsElement[1] as HTMLButtonElement).click()
// })
// inputElement.focus()
// btnsElement[0].addEventListener("click", () => {
// dialog.destroy()
// })
// btnsElement[1].addEventListener("click", () => {
// this.saveData(STORAGE_NAME, inputElement.value)
// dialog.destroy()
// })
}

private _showPublisherDialog(publisherIndex: string) {
Expand Down
10 changes: 0 additions & 10 deletions plugins/publisher-main/src/lib/Counter.svelte

This file was deleted.

26 changes: 26 additions & 0 deletions plugins/publisher-main/src/lib/preferences/GeneralSetting.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
- 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.
-->

<div>General Setting</div>
25 changes: 25 additions & 0 deletions plugins/publisher-main/src/lib/preferences/PicgoSetting.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
- 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.
-->
<div>PicgoSetting</div>
26 changes: 26 additions & 0 deletions plugins/publisher-main/src/lib/preferences/PublishSetting.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
- 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.
-->

<div>Publish Setting</div>
35 changes: 35 additions & 0 deletions plugins/publisher-main/src/routes/Preferences.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
- 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.
-->

<script lang="ts">
import PublishSetting from "../lib/preferences/PublishSetting.svelte"
import PicgoSetting from "../lib/preferences/PicgoSetting.svelte"
import GeneralSetting from "../lib/preferences/GeneralSetting.svelte"
</script>

<h1>Preferences</h1>
<GeneralSetting />
<PublishSetting />
<PicgoSetting />
26 changes: 26 additions & 0 deletions plugins/publisher-main/src/routes/Publish.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
- 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.
-->

<div>Publish</div>
Loading

0 comments on commit 70bc06b

Please sign in to comment.