From 6b3935f7f03a676ffb9f896ed7636bf52574dfc2 Mon Sep 17 00:00:00 2001 From: Benny Guo Date: Sat, 12 Aug 2023 01:23:21 +0800 Subject: [PATCH] feat: add feature to disable comment on Pages or Posts individually --- src/components/PageContent.vue | 8 +++++++- src/components/Post/PostStats.vue | 9 +++++---- src/components/Sidebar/src/Navigator.vue | 7 ++++--- src/components/Sidebar/src/Toc.vue | 5 +++-- src/models/Article.class.ts | 2 +- src/models/Post.class.ts | 2 +- src/views/Links.vue | 7 +++++-- src/views/Page.vue | 5 ++++- src/views/Post.vue | 7 +++++-- 9 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/components/PageContent.vue b/src/components/PageContent.vue index d2910403..f932f2af 100644 --- a/src/components/PageContent.vue +++ b/src/components/PageContent.vue @@ -18,6 +18,7 @@ :post-title="post.title" :current-path="currentPath" :plugin-configs="pluginConfigs" + :comments="enabledComment" ref="postStatsRef" /> @@ -64,7 +65,7 @@
- +
@@ -90,6 +91,7 @@ import { useCommonStore } from '@/stores/common' import { useRoute } from 'vue-router' import PostStats from './Post/PostStats.vue' import { useAppStore } from '@/stores/app' +import useCommentPlugin from '@/hooks/useCommentPlugin' interface PostStatsExpose extends Ref> { getCommentCount(): void @@ -119,6 +121,7 @@ export default defineComponent({ const post = toRefs(props).post const title = toRefs(props).title const postStatsRef = ref() + const { enabledCommentPlugin } = useCommentPlugin() watch( () => post.value.covers, @@ -147,6 +150,9 @@ export default defineComponent({ }) return { + enabledComment: computed( + () => post.value.comments && enabledCommentPlugin.value.plugin !== '' + ), pageTitle: computed(() => { if (title.value !== '') return title.value return post.value.title diff --git a/src/components/Post/PostStats.vue b/src/components/Post/PostStats.vue index ea66cd18..21937763 100644 --- a/src/components/Post/PostStats.vue +++ b/src/components/Post/PostStats.vue @@ -44,7 +44,7 @@ - + - + - + (undefined) diff --git a/src/components/Sidebar/src/Navigator.vue b/src/components/Sidebar/src/Navigator.vue index 20341164..802e8fac 100644 --- a/src/components/Sidebar/src/Navigator.vue +++ b/src/components/Sidebar/src/Navigator.vue @@ -16,7 +16,7 @@
  • { window.scrollTo({ @@ -57,7 +59,6 @@ export default defineComponent({ } return { - enabledPlugin: computed(() => enabledCommentPlugin.value.plugin !== ''), goBack, backToTop, jumpToComments diff --git a/src/components/Sidebar/src/Toc.vue b/src/components/Sidebar/src/Toc.vue index 747902c1..b022c697 100644 --- a/src/components/Sidebar/src/Toc.vue +++ b/src/components/Sidebar/src/Toc.vue @@ -12,7 +12,7 @@ /> - + @@ -27,7 +27,8 @@ export default defineComponent({ name: 'ObTOC', components: { SubTitle, Sticky, Navigator }, props: { - toc: String + toc: String, + comments: Boolean }, setup(props) { const tocData = toRefs(props).toc diff --git a/src/models/Article.class.ts b/src/models/Article.class.ts index 29501940..ac012cd0 100644 --- a/src/models/Article.class.ts +++ b/src/models/Article.class.ts @@ -59,7 +59,7 @@ export class Page> year: 0 } updated = '' - comments = false + comments = true path = '' covers: string | null = null excerpt: string | null = null diff --git a/src/models/Post.class.ts b/src/models/Post.class.ts index d80f9879..c6038881 100644 --- a/src/models/Post.class.ts +++ b/src/models/Post.class.ts @@ -51,7 +51,7 @@ export class Post { year: 0 } updated = '' - comments = false + comments = true path = '' excerpt: string | null = null keywords: string | null = null diff --git a/src/views/Links.vue b/src/views/Links.vue index 730a2e9a..fd7da274 100644 --- a/src/views/Links.vue +++ b/src/views/Links.vue @@ -20,6 +20,7 @@ :post-title="pageData.title" :current-path="currentPath" :plugin-configs="pluginConfigs" + :comments="enabledComment" ref="postStatsRef" /> @@ -117,7 +118,6 @@ import LinkCategoryList from '@/components/Link/LinkCategoryList.vue' import LinkList from '@/components/Link/LinkList.vue' import Comment from '@/components/Comment.vue' import Breadcrumbs from '@/components/Breadcrumbs.vue' -import { useMetaStore } from '@/stores/meta' import usePageTitle from '@/hooks/usePageTitle' import useJumpToEle from '@/hooks/useJumpToEle' import useCommentPlugin from '@/hooks/useCommentPlugin' @@ -173,7 +173,10 @@ export default defineComponent({ gradientBackground: computed(() => { return { background: appStore.themeConfig.theme.header_gradient_css } }), - enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''), + enabledComment: computed( + () => + pageData.value.comments && enabledCommentPlugin.value.plugin !== '' + ), pageTitle, jumpToContent, postStatsRef, diff --git a/src/views/Page.vue b/src/views/Page.vue index f8e303b3..0b0cb96e 100644 --- a/src/views/Page.vue +++ b/src/views/Page.vue @@ -83,7 +83,10 @@ export default defineComponent({ onBeforeMount(fetchArticle) return { - enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''), + enabledComment: computed( + () => + pageData.value.comments && enabledCommentPlugin.value.plugin !== '' + ), pageTitle: computed(() => pageTitle.value), pageData, t diff --git a/src/views/Post.vue b/src/views/Post.vue index aa107aff..b1cb12e3 100644 --- a/src/views/Post.vue +++ b/src/views/Post.vue @@ -91,6 +91,7 @@ :post-title="post.title" :current-path="currentPath" :plugin-configs="pluginConfigs" + :comments="enabledComment" ref="postStatsRef" /> @@ -166,7 +167,7 @@
    - +
    @@ -268,7 +269,9 @@ export default defineComponent({ isMobile: computed(() => commonStore.isMobile), currentPath: computed(() => route.path), pluginConfigs: computed(() => appStore.themeConfig.plugins), - enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''), + enabledComment: computed( + () => post.value.comments && enabledCommentPlugin.value.plugin !== '' + ), postStatsRef, SvgTypes, commonStore,