Skip to content

Commit

Permalink
feat: hide comments if all plugins are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyxguo committed Aug 11, 2023
1 parent af82e99 commit 9b0db10
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/views/Links.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
</div>
</div>

<template v-if="pageData.title && pageData.text && pageData.uid">
<template
v-if="enabledComment && pageData.title && pageData.text && pageData.uid"
>
<div id="comments">
<Comment
:title="pageData.title"
Expand Down Expand Up @@ -118,6 +120,7 @@ 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'
interface PostStatsExpose extends Ref<InstanceType<typeof PostStats>> {
getCommentCount(): void
Expand Down Expand Up @@ -145,10 +148,9 @@ export default defineComponent({
const postStatsRef = ref<PostStatsExpose>()
const route = useRoute()
const { t } = useI18n()
const commentOffset = ref(0)
const contentEl = ref()
const { pageTitle, updateTitle } = usePageTitle()
const { jumpToEle } = useJumpToEle()
const { enabledCommentPlugin } = useCommentPlugin()
const fetchArticle = async () => {
pageData.value = await articleStore.fetchArticle('friends')
Expand All @@ -171,6 +173,7 @@ export default defineComponent({
gradientBackground: computed(() => {
return { background: appStore.themeConfig.theme.header_gradient_css }
}),
enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''),
pageTitle,
jumpToContent,
postStatsRef,
Expand Down
19 changes: 12 additions & 7 deletions src/views/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
<div>
<Breadcrumbs :current="pageTitle" />
<PageContent :post="pageData" :title="pageTitle">
<div id="comments">
<Comment
:title="pageData.title"
:body="pageData.text"
:uid="pageData.uid"
/>
</div>
<template v-if="enabledComment">
<div id="comments">
<Comment
:title="pageData.title"
:body="pageData.text"
:uid="pageData.uid"
/>
</div>
</template>
</PageContent>
</div>
</template>
Expand All @@ -31,6 +33,7 @@ import { useMetaStore } from '@/stores/meta'
import PageContent from '@/components/PageContent.vue'
import Breadcrumbs from '@/components/Breadcrumbs.vue'
import Comment from '@/components/Comment.vue'
import useCommentPlugin from '@/hooks/useCommentPlugin'
declare const Prism: any
Expand All @@ -45,6 +48,7 @@ export default defineComponent({
const route = useRoute()
const { t } = useI18n()
const pageTitle = ref()
const { enabledCommentPlugin } = useCommentPlugin()
const fetchArticle = async () => {
const response = await articleStore.fetchArticle(
Expand Down Expand Up @@ -79,6 +83,7 @@ export default defineComponent({
onBeforeMount(fetchArticle)
return {
enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''),
pageTitle: computed(() => pageTitle.value),
pageData,
t
Expand Down
5 changes: 4 additions & 1 deletion src/views/Post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<Article :data="post.next_post" />
</div>
</div>
<template v-if="post.title && post.text && post.uid">
<template v-if="enabledComment && post.title && post.text && post.uid">
<div id="comments">
<Comment :title="post.title" :body="post.text" :uid="post.uid" />
</div>
Expand Down Expand Up @@ -189,6 +189,7 @@ import { useAppStore } from '@/stores/app'
import { useCommonStore } from '@/stores/common'
import SvgIcon, { SvgTypes } from '@/components/SvgIcon/index.vue'
import PostStats from '@/components/Post/PostStats.vue'
import useCommentPlugin from '@/hooks/useCommentPlugin'
interface PostStatsExpose extends Ref<InstanceType<typeof PostStats>> {
getCommentCount(): void
Expand Down Expand Up @@ -219,6 +220,7 @@ export default defineComponent({
const post = ref(new Post())
const loading = ref(true)
const postStatsRef = ref<PostStatsExpose>()
const { enabledCommentPlugin } = useCommentPlugin()
const fetchData = async () => {
loading.value = true
Expand Down Expand Up @@ -266,6 +268,7 @@ export default defineComponent({
isMobile: computed(() => commonStore.isMobile),
currentPath: computed(() => route.path),
pluginConfigs: computed(() => appStore.themeConfig.plugins),
enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''),
postStatsRef,
SvgTypes,
commonStore,
Expand Down

0 comments on commit 9b0db10

Please sign in to comment.