Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more link rule #407

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
NUXT_PUBLIC_DEFAULT_TYPE=siyuan
NUXT_PUBLIC_SIYUAN_API_URL=http://127.0.0.1:6806
NUXT_PUBLIC_WAIT_TIME=500
NUXT_PUBLIC_PROVIDER_MODE=false
NUXT_PUBLIC_PROVIDER_URL=
# ======= public vars =======

# ======= private vars =======
Expand Down
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ Based on the localization concept of siyuan-note , this plugin is natively share
The core idea of this plugin is: `Everything is a Page` . You can set a page to be the home page.

> Important Notice:
> 1. Version 2.0.0 introduces support for VIP versions, distinguished as follows:
/s/[id] - Regular Link
/static/[id] - Regular Link
/p/[id] - Regular Link
/post/[id] - Regular Link
-----------------------------------------------------------------------------------
/doc/[id] - VIP Exclusive Link, "Only used when deploying in VIP Service Provider mode"
/article/[id] - VIP Exclusive Link, "Only used when deploying in VIP Service Provider mode"
/share/[id] - VIP Exclusive Link, "Only used when deploying in VIP Service Provider mode"
/x/[id] - VIP Exclusive Link, "Only used when deploying in VIP Service Provider mode"
/a/[id] - VIP Exclusive Link, "Only used when deploying in VIP Service Provider mode"
/d/[id] - VIP Exclusive Link, "Only used when deploying in VIP Service Provider mode"
> 1. Version 2.0.0 introduces support for VIP versions, add mode link rules as follows:
/s/[id]
/static/[id]
/p/[id]
/post/[id]
/link/[id]
/doc/[id]
/article/[id]
/x/[id]
/a/[id]
/d/[id]

[docs](https://blog.terwer.space/s/20230621001422-xsimx5v)

Expand Down
23 changes: 11 additions & 12 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
本插件的核心理念是:`一切皆页面` 。您可以设置某个页面为主页。

> 重要提示:
> 1. 2.0.0,新增适配 VIP 版本,并区分如下:
/s/[id] - 普通链接
/static/[id] - 普通链接
/p/[id] - 普通链接
/post/[id] - 普通链接
-----------------------------------------------------------------------------------
/doc/[id] - VIP 专属链接,「仅 VIP 服务商模式部署时使用」
/article/[id] - VIP 专属链接,「仅 VIP 服务商模式部署时使用」
/share/[id] - VIP 专属链接,「仅 VIP 服务商模式部署时使用」
/x/[id] - VIP 专属链接,「仅 VIP 服务商模式部署时使用」
/a/[id] - VIP 专属链接,「仅 VIP 服务商模式部署时使用」
/d/[id] - VIP 专属链接,「仅 VIP 服务商模式部署时使用」
> 1. 2.0.0,新增适配 VIP 版本,新增更多链接形式如下:
/s/[id]
/static/[id]
/p/[id]
/post/[id]
/link/[id]
/doc/[id]
/article/[id]
/x/[id]
/a/[id]
/d/[id]

[帮助文档](https://blog.terwer.space/s/20230621001422-xsimx5v)

Expand Down
4 changes: 2 additions & 2 deletions components/static/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { createAppLogger } from "~/common/appLogger"
import { checkExpires, getSummery } from "~/utils/utils"
import { useServerAssets } from "~/plugins/renderer/useServerAssets"
import { useAuthModeFetch } from "~/composables/useAuthModeFetch"
import { useProviderMode } from "~/composables/useProviderMode"

// https://github.com/nuxt/nuxt/issues/15346
// 由于布局是个宏,静态构建情况下,不能动态设置,只能在前面的页面写死
Expand All @@ -45,13 +46,12 @@ const props = defineProps({
})

const logger = createAppLogger("static-share-page")
const env = useRuntimeConfig()
const { t } = useI18n()
const route = useRoute()
const id = props.pageId ?? ((route.params.id ?? "") as string)
const providerMode = env.public.providerMode === "true"
const { getFirstImageSrc } = useServerAssets()
const { fetchPostMeta } = useAuthModeFetch()
const { providerMode } = useProviderMode()

// datas
const formData = reactive({
Expand Down
7 changes: 2 additions & 5 deletions components/static/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import { JsonUtil } from "zhi-common"
import AppConfig from "~/app.config"
import { useAuthModeFetch } from "~/composables/useAuthModeFetch"
import { useRoute } from "vue-router"
import { useProviderMode } from "~/composables/useProviderMode"

const env = useRuntimeConfig()
const providerMode = env.public.providerMode === "true"
const { providerMode } = useProviderMode()
const { fetchConfig } = useAuthModeFetch()
const resText = await fetchConfig(`static.app.config.json`, providerMode)
const setting = JsonUtil.safeParse<typeof AppConfig>(resText, {} as typeof AppConfig)
console.log(resText)
console.log(setting)
await useStaticThemeMode()

const VNode = () =>
Expand Down
4 changes: 3 additions & 1 deletion composables/useAuthModeFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export const useAuthModeFetch = () => {
})
const resJson = await res.json()
if (resJson.code === 0) {
resText = JSON.stringify(resJson.data)
const dataJson = JSON.parse(resJson.data)
resText = JSON.stringify(dataJson.post)
} else {
ElMessage.error("文档获取失败,错误信息如下=>" + resJson.msg)
}
Expand Down Expand Up @@ -108,6 +109,7 @@ export const useAuthModeFetch = () => {
}

const fetchConfig = async (filename: string, providerMode: boolean): Promise<string> => {
console.log("providerMode=>", providerMode)
let resText: string
if (providerMode) {
logger.info(`fetch config text ${filename} in provider mode`)
Expand Down
4 changes: 2 additions & 2 deletions composables/useCommonShareType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import { createAppLogger } from "~/common/appLogger"
import { useSiyuanApi } from "~/composables/api/useSiyuanApi"
import { useAuthModeFetch } from "~/composables/useAuthModeFetch"
import { usePost } from "~/composables/usePost"
import { useProviderMode } from "~/composables/useProviderMode"

export const useCommonShareType = () => {
const logger = createAppLogger("use-common-share-type")
const { kernelApi } = useSiyuanApi()
const { fetchConfig } = useAuthModeFetch()
const { providerMode } = useProviderMode()
const shareTypeJsonFile = "share-type.json"
const route = useRoute()
const env = useRuntimeConfig()
const providerMode = env.public.providerMode === "true"

/**
* 获取分享类型
Expand Down
9 changes: 9 additions & 0 deletions composables/useProviderMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createAppLogger } from "~/common/appLogger"

export const useProviderMode = () => {
const logger = createAppLogger("use-auth-mode-fetch")
const env = useRuntimeConfig()
const providerMode = env.public.providerMode === "true" || env.public.providerMode === true
logger.debug(`check in providerMode => ${providerMode}`)
return { providerMode }
}
4 changes: 2 additions & 2 deletions composables/useStaticThemeMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useRoute } from "vue-router"
import { useAuthModeFetch } from "~/composables/useAuthModeFetch"
import { JsonUtil } from "zhi-common"
import AppConfig from "~/app.config"
import { useProviderMode } from "~/composables/useProviderMode"

// 创建日志记录器
const logger = createAppLogger("use-theme-mode")
Expand All @@ -40,9 +41,8 @@ const logger = createAppLogger("use-theme-mode")
export const useStaticThemeMode = async () => {
// 获取颜色模式和运行时配置
const color = useColorMode()
const env = useRuntimeConfig()
const { query } = useRoute()
const providerMode = env.public.providerMode === "true"
const { providerMode } = useProviderMode()
const appBase = process.env.APP_BASE
const { fetchConfig } = useAuthModeFetch()

Expand Down
4 changes: 2 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export default defineNuxtConfig({
defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE ?? "siyuan",
siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL ?? "http://127.0.0.1:6806",
waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
providerMode: process.env.NUXT_PROVIDER_MODE ?? "false",
providerUrl: process.env.NUXT_PROVIDER_URL ?? "http://127.0.0.1:8000",
providerMode: process.env.NUXT_PUBLIC_PROVIDER_MODE ?? "false",
providerUrl: process.env.NUXT_PUBLIC_PROVIDER_URL ?? "http://127.0.0.1:8000",
},
},

Expand Down
4 changes: 2 additions & 2 deletions nuxt.node.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export default defineNuxtConfig({
defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE ?? "siyuan",
siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL ?? "http://127.0.0.1:6806",
waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
providerMode: process.env.NUXT_PROVIDER_MODE ?? "false",
providerUrl: process.env.NUXT_PROVIDER_URL ?? "http://127.0.0.1:8000",
providerMode: process.env.NUXT_PUBLIC_PROVIDER_MODE ?? "false",
providerUrl: process.env.NUXT_PUBLIC_PROVIDER_URL ?? "http://127.0.0.1:8000",
},
},

Expand Down
4 changes: 2 additions & 2 deletions nuxt.vercel.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export default defineNuxtConfig({
defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE,
siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL,
waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
providerMode: process.env.NUXT_PROVIDER_MODE,
providerUrl: process.env.NUXT_PROVIDER_URL,
providerMode: process.env.NUXT_PUBLIC_PROVIDER_MODE,
providerUrl: process.env.NUXT_PUBLIC_PROVIDER_URL,
},
},

Expand Down
File renamed without changes.
33 changes: 33 additions & 0 deletions pages/article/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
- 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 setup lang="ts">
definePageMeta({
layout: false,
})
</script>

<template>
<static-detail-page />
</template>
33 changes: 33 additions & 0 deletions pages/d/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
- 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 setup lang="ts">
definePageMeta({
layout: false,
})
</script>

<template>
<static-detail-page />
</template>
33 changes: 33 additions & 0 deletions pages/doc/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
- 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 setup lang="ts">
definePageMeta({
layout: false,
})
</script>

<template>
<static-detail-page />
</template>
33 changes: 33 additions & 0 deletions pages/link/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
- 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 setup lang="ts">
definePageMeta({
layout: false,
})
</script>

<template>
<static-detail-page />
</template>
33 changes: 33 additions & 0 deletions pages/x/[id].vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
- 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 setup lang="ts">
definePageMeta({
layout: false,
})
</script>

<template>
<static-detail-page />
</template>
Loading
Loading