Skip to content

Commit

Permalink
feat: 重构项目,统一处理公开分享与授权码模式下的分享逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jul 2, 2023
1 parent f65dd77 commit 6c0c651
Show file tree
Hide file tree
Showing 33 changed files with 1,392 additions and 520 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ The core idea of this plugin is: `Everything is a Page` . You can set a page to

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

> Important: Due to the 1.7.0+ new authorization code mode sharing dependency 2.9.3 ontology changes, this version only supports more than 2.9.3+ clients, lower than this version, please use the old version of the plugin!
## Core Features

* **One-click sharing**: You can share your documents to the local area network with just one click. If you need to share remotely, you can deploy it on a server using Docker and then install the plugin.
Expand Down Expand Up @@ -50,6 +48,7 @@ The core idea of this plugin is: `Everything is a Page` . You can set a page to
- [ ] echats chart support
- [ ] Support svg with svOrigin, e.g. '<use xlink:href="#iconMore'>'</use>
- [X] Support enabling sharing under authorization code (experimental)
- [X] Unordered list style adaptation

## Changelog

Expand Down
5 changes: 2 additions & 3 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

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

> 重要提示:由于 1.7.0+ 新增的 `授权码模式分享(实验性)` 依赖 2.9.3 本体改动,此版本仅支持 2.9.3+ 以上客户端,低于此版本,请使用旧版插件!
## 核心特色

- **一键分享**:支持一键分享文档到局域网,如果需要远程分享,可使用 docker 部署在服务器,然后安装插件
Expand Down Expand Up @@ -49,7 +47,8 @@
- [ ] plantuml 图表支持
- [ ] echats 图表支持
- [ ] 支持思源自带的svg,例如 `<use xlink:href="#iconMore"></use>`
- [X] 支持开启授权码下的分享(实验性)
- [X] 支持开启授权码下的分享
- [X] 无序列表样式适配

## 更新历史

Expand Down
4 changes: 4 additions & 0 deletions components/default/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import { useServerAssets } from "~/plugins/renderer/useServerAssets"
const logger = createAppLogger("share-page")
definePageMeta({
layout: "default",
})
// props
const props = defineProps({
showTitleSign: Boolean,
Expand Down
44 changes: 44 additions & 0 deletions components/default/DetailPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
- 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">
// https://github.com/nuxt/nuxt/issues/15346
// 由于布局是个宏,不能动态设置了,因此只能写死
</script>

<template>
<el-container>
<default-header />
<el-main>
<default-detail :show-title-sign="true" />
</el-main>
<default-footer />
</el-container>
</template>

<style lang="stylus">
.el-container
display block !important
</style>
46 changes: 46 additions & 0 deletions components/default/Home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
- 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">
// props
const props = defineProps({
pageId: {
type: String,
default: undefined,
},
})
</script>

<template>
<el-container>
<default-header />
<el-main>
<default-detail :page-id="props.pageId" :override-seo="true" />
</el-main>
<default-footer />
</el-container>
</template>

<style scoped></style>
66 changes: 66 additions & 0 deletions components/default/HomePage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--
- 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">
import { useSettingStore } from "~/stores/useSettingStore"
import { StrUtil } from "zhi-common"
definePageMeta({
layout: "default",
})
const { t } = useI18n()
const { getSetting } = useSettingStore()
const setting = await getSetting()
const title = `${setting?.siteTitle ?? t("blog.site.title")} - ${setting?.siteSlogan ?? t("blog.site.slogan")}`
const seoMeta = {
title: title,
ogTitle: title,
description: setting?.siteDescription,
ogDescription: setting?.siteDescription,
} as any
useSeoMeta(seoMeta)
const homePageId = setting?.homePageId ?? undefined
// methods
const goSetting = async () => {
await navigateTo("/setting")
}
</script>

<template>
<div v-if="StrUtil.isEmptyString(homePageId)">
<el-empty :description="t('blog.index.no.home')">
<el-button type="primary" @click="goSetting">{{ t("blog.index.goto.set.home") }}</el-button>
</el-empty>
</div>
<div v-else>
<default-home :page-id="homePageId" />
</div>
</template>

<style scoped></style>
124 changes: 124 additions & 0 deletions components/static/Detail.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!--
- 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">
import { JsonUtil, ObjectUtil } from "zhi-common"
import { Post } from "zhi-blog-api"
import { createAppLogger } from "~/common/appLogger"
import { getSummery } from "~/utils/utils"
import { useServerAssets } from "~/plugins/renderer/useServerAssets"
// https://github.com/nuxt/nuxt/issues/15346
// 由于布局是个宏,静态构建情况下,不能动态设置,只能在前面的页面写死
// props
const props = defineProps({
showTitleSign: Boolean,
overrideSeo: Boolean,
pageId: {
type: String,
default: undefined,
},
})
const logger = createAppLogger("static-share-page")
const { t } = useI18n()
const route = useRoute()
const id = props.pageId ?? ((route.params.id ?? "") as string)
const { getFirstImageSrc } = useServerAssets()
// datas
const getPostData = async () => {
const mdResponse = await fetch(`/public/siyuan-blog/${id}.json`)
const mdText = await mdResponse.text()
formData.post = JsonUtil.safeParse<Post>(mdText, {} as Post)
formData.shareEnabled = !ObjectUtil.isEmptyObject(formData.post)
logger.info("post=>", formData.post)
logger.info(`shareEnabled=>${formData.shareEnabled}`)
}
const formData = reactive({
post: {} as Post,
shareEnabled: true,
})
await getPostData()
if (!props.overrideSeo) {
const titleSign = " - " + t("blog.share")
const title = `${formData?.post?.title ?? "404 Not Found"}${props.showTitleSign ? titleSign : ""}`
const desc = getSummery(formData?.post?.description ?? "")
const headImage = getFirstImageSrc(formData?.post?.description ?? "")
const seoMeta = {
title: title,
ogTitle: title,
description: desc,
ogDescription: desc,
} as any
if (headImage) {
logger.info("get a head image from doc=>", headImage)
seoMeta.ogImage = headImage
}
useSeoMeta(seoMeta)
}
onMounted(async () => {})
const VNode = () =>
h("div", {
class: "",
innerHTML: formData.post.editorDom?.replaceAll('contenteditable="true"', 'contenteditable="false"') ?? "",
})
</script>

<template>
<div v-if="!formData.shareEnabled">
<el-empty :description="t('blog.index.no.permission')"> </el-empty>
</div>
<div v-else class="fn__flex-1 protyle" data-loading="finished">
<div class="protyle-content protyle-content--transition" data-fullwidth="true">
<div class="protyle-title protyle-wysiwyg--attr">
<div
contenteditable="false"
data-position="center"
spellcheck="false"
class="protyle-title__input"
data-render="true"
>
{{ formData.post.title }}
</div>
</div>
<div
class="protyle-wysiwyg protyle-wysiwyg--attr"
spellcheck="false"
contenteditable="false"
data-doc-type="NodeDocument"
>
<VNode v-highlight v-sbeauty v-sdomparser />
</div>
</div>
</div>
</template>

<style scoped></style>
44 changes: 44 additions & 0 deletions components/static/DetailPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
- 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">
// https://github.com/nuxt/nuxt/issues/15346
// 由于布局是个宏,不能动态设置了,因此只能写死
</script>

<template>
<el-container>
<static-header />
<el-main>
<static-detail :show-title-sign="true" />
</el-main>
<static-footer />
</el-container>
</template>

<style lang="stylus">
.el-container
display block !important
</style>
Loading

0 comments on commit 6c0c651

Please sign in to comment.