Skip to content

Commit

Permalink
feat: 新增思源配置
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 12, 2023
1 parent d081734 commit 202c2ce
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 8 deletions.
62 changes: 62 additions & 0 deletions src/components/set/SiyuanSetting.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
- 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" setup>
import { useVueI18n } from "~/src/composables/useVueI18n.ts"
import { useSiyuanSetting } from "~/src/stores/useSiyuanSetting.ts"
const { t } = useVueI18n()
const { getSiyuanSetting } = useSiyuanSetting()
const siyuanSettingForm = getSiyuanSetting()
</script>

<template>
<back-page title="思源笔记设置">
<el-form label-width="125px" class="siyuan-setting-form">
<el-form-item :label="t('setting.blog.siyuan.apiurl')" prop="apiUrl">
<el-input
v-model="siyuanSettingForm.apiUrl"
autocomplete="off"
:placeholder="t('setting.blog.siyuan.apiurl.tip')"
/>
</el-form-item>
<el-form-item :label="t('setting.blog.siyuan.password')" prop="pwd">
<el-input
v-model="siyuanSettingForm.password"
type="password"
autocomplete="off"
:placeholder="t('setting.blog.siyuan.password.tip')"
show-password
/>
</el-form-item>
</el-form>
</back-page>
</template>

<style lang="stylus" scoped>
.siyuan-setting-form
margin-top 20px
</style>
5 changes: 5 additions & 0 deletions src/composables/useVueRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import PlatformAddForm from "~/src/components/set/publish/PlatformAddForm.vue"
import PlatformUpdateForm from "~/src/components/set/publish/PlatformUpdateForm.vue"
import PlatformQuickAdd from "~/src/components/set/publish/PlatformQuickAdd.vue"
import QuickPublish from "~/src/workers/QuickPublish.vue"
import SiyuanSetting from "~/src/components/set/SiyuanSetting.vue"

const ApiTest = () => import("~/src/pages/ApiTest.vue")
const SiyuanTest = () => import("~/src/components/test/SiyuanTest.vue")
Expand Down Expand Up @@ -100,6 +101,10 @@ const routes: RouteRecordRaw[] = [
path: "/setting/general",
component: GeneralSetting,
},
{
path: "/setting/siyuan",
component: SiyuanSetting,
},
]

export const useVueRouter = (): Router => {
Expand Down
14 changes: 11 additions & 3 deletions src/layouts/default/DefaultFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
{{ t("blog.newwin.open") }}
</span>

<!--
-----------------------------------------------------------------------------
-->
<span class="text">.</span>
<span class="text s-dark" @click="handleSiyuanSetting">
{{ t("siyuan.config.setting") }}
</span>
</div>
</div>
</div>
Expand Down Expand Up @@ -101,6 +102,13 @@ const newWin = () => {
const url = rt.getURL("/index.html#/")
window.open(url)
}
const handleSiyuanSetting = async () => {
await router.push({
path: "/setting/siyuan",
query: { showBack: "true" },
})
}
</script>

<style scoped>
Expand Down
8 changes: 5 additions & 3 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ export default {
"It is currently in the pendant mode. Starting from version 0.1.0, there is no need to reference the pendant on all pages. You only need to reference a pendant on the parent page. The specific rules are as follows: 1. If there are no subsidiaries, it will be compatible with the previous method of version 0.0.3 to display the release page of the current document. 2. If a subsidiary document is detected, all the subsidiaries will be displayed in a list and paging. You can choose a sub -document separately for release operations.",
"blog.newwin.open": "Open in a new window",
"blog.change.siyuan.api": "Modify Siyuan API address",
"setting.blog.siyuan.password": "Siyuan Note token, please copying from【set up-> about 】",
"setting.blog.siyuan.apiurl":
"The API address of Siyuan Note, including ports, for example: http://127.0.0.0.1: 6806",
"setting.blog.siyuan.current.apiurl": "Current apiUrl=>",
"setting.conf.export": "Export config",
"setting.conf.import": "Import config",
Expand Down Expand Up @@ -545,4 +542,9 @@ export default {
"main.data.empty": "No data",
"enableKnowledgeSpace.Tips": "After validation, a list of available knowledge spaces is listed, and you can modify the default knowledge spaces as needed and save them",
"post.bind.auto.tips": "The ID here is automatically saved by the publishing tool, if you are not clear about the principle, please do not modify it",
"siyuan.config.setting": "Source settings",
"setting.blog.siyuan.apiurl": "Siyuan API address",
"setting.blog.siyuan.apiurl.tip": "The API address of Siyuan Note, including ports, The default address of Siyuan API is: http://127.0.0.1;6806",
"setting.blog.siyuan.password": "Siyuan Token",
"setting.blog.siyuan.password.tip": "Siyuan Token, which is empty by default",
}
7 changes: 5 additions & 2 deletions src/locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ export default {
"温馨提示:1、当前处于挂件模式,从 0.1.0 版本开始,无需在所有页面引用挂件了,只需要在父级页面引用一个挂件即可。具体规则如下:(1). 如果检测到没有子文档,会兼容 0.0.3 版本以前的方式,展示当前文档的发布页面。 (2). 如果检测到有子文档,会以列表加分页的方式展示所有子文档列表。可单独选择某个子文档进行发布操作。 2、升级新版之前强烈建议导出配置,防止配置丢失。 3、如果出现新版本不兼容的异常情况,建议清空配置。此操作不可恢复,请谨慎操作!",
"blog.newwin.open": "页签模式",
"blog.change.siyuan.api": "思源地址",
"setting.blog.siyuan.password": "思源笔记鉴权Token,请从【设置->关于】复制,如果是本地笔记留空即可",
"setting.blog.siyuan.apiurl": "思源笔记的API地址,包括端口,例如:http://127.0.0.1:6806",
"setting.blog.siyuan.current.apiurl": "当前API地址=>",
"setting.blog.middlewareUrl": "跨域请求代理",
"setting.blog.middlewareUrl.tip": "某些场景下需要(例如自部署模式,Nginx伺服等、vite开发环境伺服等),其他情况可忽略",
Expand Down Expand Up @@ -536,4 +534,9 @@ export default {
"enableKnowledgeSpace.Tips":
"验证通过之后,将列出可用的 [[knowledge-space-title]] 列表,您可以根据需要修改默认 [[knowledge-space-title]] 并保存",
"post.bind.auto.tips": "此处ID为发布工具自动保存,仅作为修复数据使用,如果您不清楚原理,请勿修改",
"siyuan.config.setting": "思源设置",
"setting.blog.siyuan.apiurl": "思源API地址",
"setting.blog.siyuan.apiurl.tip": "思源笔记的API地址,包括端口,默认是:http://127.0.0.1:6806",
"setting.blog.siyuan.password": "思源Token",
"setting.blog.siyuan.password.tip": "思源笔记鉴权Token,请从【设置->关于】复制,如果是本地笔记留空即可",
}
53 changes: 53 additions & 0 deletions src/stores/useSiyuanSetting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 { SiyuanConfig } from "zhi-siyuan-api"
import { RemovableRef, StorageSerializers, useLocalStorage } from "@vueuse/core"

const useSiyuanSetting = () => {
const storageKey = "siyuan-cfg"

/**
* 获取思源笔记配置
*
* @author terwer
* @since 0.6.0
*/
const getSiyuanSetting = (): RemovableRef<SiyuanConfig> => {
let baseUrl = "http://127.0.0.1:6806"
let token = ""
let middlewareUrl = "https://api.terwer.space/api/middleware"
const initialValue = new SiyuanConfig(baseUrl, token)
initialValue.middlewareUrl = middlewareUrl
const siyuanConfig = useLocalStorage<SiyuanConfig>(storageKey, initialValue, {
serializer: StorageSerializers.object,
})
return siyuanConfig
}

return { getSiyuanSetting }
}

export { useSiyuanSetting }

0 comments on commit 202c2ce

Please sign in to comment.