Skip to content

Commit 6b3935f

Browse files
committed
feat: add feature to disable comment on Pages or Posts individually
1 parent 8372e21 commit 6b3935f

File tree

9 files changed

+35
-17
lines changed

9 files changed

+35
-17
lines changed

src/components/PageContent.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
:post-title="post.title"
1919
:current-path="currentPath"
2020
:plugin-configs="pluginConfigs"
21+
:comments="enabledComment"
2122
ref="postStatsRef"
2223
/>
2324
</div>
@@ -64,7 +65,7 @@
6465
<div class="col-span-1">
6566
<Sidebar>
6667
<Profile author="blog-author" />
67-
<Toc :toc="post.toc" />
68+
<Toc :toc="post.toc" :comments="enabledComment" />
6869
</Sidebar>
6970
</div>
7071
</div>
@@ -90,6 +91,7 @@ import { useCommonStore } from '@/stores/common'
9091
import { useRoute } from 'vue-router'
9192
import PostStats from './Post/PostStats.vue'
9293
import { useAppStore } from '@/stores/app'
94+
import useCommentPlugin from '@/hooks/useCommentPlugin'
9395
9496
interface PostStatsExpose extends Ref<InstanceType<typeof PostStats>> {
9597
getCommentCount(): void
@@ -119,6 +121,7 @@ export default defineComponent({
119121
const post = toRefs(props).post
120122
const title = toRefs(props).title
121123
const postStatsRef = ref<PostStatsExpose>()
124+
const { enabledCommentPlugin } = useCommentPlugin()
122125
123126
watch(
124127
() => post.value.covers,
@@ -147,6 +150,9 @@ export default defineComponent({
147150
})
148151
149152
return {
153+
enabledComment: computed(
154+
() => post.value.comments && enabledCommentPlugin.value.plugin !== ''
155+
),
150156
pageTitle: computed(() => {
151157
if (title.value !== '') return title.value
152158
return post.value.title

src/components/Post/PostStats.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</span>
4545
</span>
4646
</span>
47-
<span v-if="plugin === 'waline'">
47+
<span v-if="comments && plugin === 'waline'">
4848
<SvgIcon
4949
class="h-5 w-5"
5050
icon-class="quote"
@@ -74,7 +74,7 @@
7474
<ob-skeleton width="40px" height="16px" />
7575
</span>
7676
</span>
77-
<span v-if="plugin === 'twikoo'">
77+
<span v-if="comments && plugin === 'twikoo'">
7878
<SvgIcon
7979
class="h-5 w-5"
8080
icon-class="quote"
@@ -157,7 +157,7 @@
157157
<ob-skeleton width="40px" height="16px" />
158158
</span>
159159
</span>
160-
<span v-if="plugin === 'waline' || plugin === 'twikoo'">
160+
<span v-if="comments && (plugin === 'waline' || plugin === 'twikoo')">
161161
<SvgIcon
162162
icon-class="quote"
163163
fill="none"
@@ -200,7 +200,8 @@ export default defineComponent({
200200
type: String,
201201
default: '/',
202202
required: true
203-
}
203+
},
204+
comments: Boolean
204205
},
205206
setup(props, { expose }) {
206207
const commentCount = ref<number | undefined>(undefined)

src/components/Sidebar/src/Navigator.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<SvgIcon class="inline-block text-3xl" icon-class="back-to-top" />
1717
</li>
1818
<li
19-
v-if="enabledPlugin"
19+
v-if="comments"
2020
class="flex justify-center py-3 w-full hover:opacity-50 hover:text-ob transition-all cursor-pointer"
2121
@click="jumpToComments"
2222
data-dia="jump-to-comment"
@@ -36,10 +36,12 @@ import useCommentPlugin from '@/hooks/useCommentPlugin'
3636
export default defineComponent({
3737
name: 'Navigator',
3838
components: { SvgIcon },
39+
props: {
40+
comments: Boolean
41+
},
3942
setup() {
4043
const router = useRouter()
4144
const { jumpToEle } = useJumpToEle()
42-
const { enabledCommentPlugin } = useCommentPlugin()
4345
4446
const backToTop = () => {
4547
window.scrollTo({
@@ -57,7 +59,6 @@ export default defineComponent({
5759
}
5860
5961
return {
60-
enabledPlugin: computed(() => enabledCommentPlugin.value.plugin !== ''),
6162
goBack,
6263
backToTop,
6364
jumpToComments

src/components/Sidebar/src/Toc.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/>
1313
</div>
1414
</transition>
15-
<Navigator />
15+
<Navigator :comments="comments" />
1616
</div>
1717
</Sticky>
1818
</template>
@@ -27,7 +27,8 @@ export default defineComponent({
2727
name: 'ObTOC',
2828
components: { SubTitle, Sticky, Navigator },
2929
props: {
30-
toc: String
30+
toc: String,
31+
comments: Boolean
3132
},
3233
setup(props) {
3334
const tocData = toRefs(props).toc

src/models/Article.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class Page<DataType = Link[] | Record<string, Link[]>>
5959
year: 0
6060
}
6161
updated = ''
62-
comments = false
62+
comments = true
6363
path = ''
6464
covers: string | null = null
6565
excerpt: string | null = null

src/models/Post.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class Post {
5151
year: 0
5252
}
5353
updated = ''
54-
comments = false
54+
comments = true
5555
path = ''
5656
excerpt: string | null = null
5757
keywords: string | null = null

src/views/Links.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
:post-title="pageData.title"
2121
:current-path="currentPath"
2222
:plugin-configs="pluginConfigs"
23+
:comments="enabledComment"
2324
ref="postStatsRef"
2425
/>
2526
</div>
@@ -117,7 +118,6 @@ import LinkCategoryList from '@/components/Link/LinkCategoryList.vue'
117118
import LinkList from '@/components/Link/LinkList.vue'
118119
import Comment from '@/components/Comment.vue'
119120
import Breadcrumbs from '@/components/Breadcrumbs.vue'
120-
import { useMetaStore } from '@/stores/meta'
121121
import usePageTitle from '@/hooks/usePageTitle'
122122
import useJumpToEle from '@/hooks/useJumpToEle'
123123
import useCommentPlugin from '@/hooks/useCommentPlugin'
@@ -173,7 +173,10 @@ export default defineComponent({
173173
gradientBackground: computed(() => {
174174
return { background: appStore.themeConfig.theme.header_gradient_css }
175175
}),
176-
enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''),
176+
enabledComment: computed(
177+
() =>
178+
pageData.value.comments && enabledCommentPlugin.value.plugin !== ''
179+
),
177180
pageTitle,
178181
jumpToContent,
179182
postStatsRef,

src/views/Page.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ export default defineComponent({
8383
onBeforeMount(fetchArticle)
8484
8585
return {
86-
enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''),
86+
enabledComment: computed(
87+
() =>
88+
pageData.value.comments && enabledCommentPlugin.value.plugin !== ''
89+
),
8790
pageTitle: computed(() => pageTitle.value),
8891
pageData,
8992
t

src/views/Post.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
:post-title="post.title"
9292
:current-path="currentPath"
9393
:plugin-configs="pluginConfigs"
94+
:comments="enabledComment"
9495
ref="postStatsRef"
9596
/>
9697
</div>
@@ -166,7 +167,7 @@
166167
<div>
167168
<Sidebar>
168169
<Profile :author="post.author.slug || ''" />
169-
<Toc :toc="post.toc" />
170+
<Toc :toc="post.toc" :comments="enabledComment" />
170171
</Sidebar>
171172
</div>
172173
</div>
@@ -268,7 +269,9 @@ export default defineComponent({
268269
isMobile: computed(() => commonStore.isMobile),
269270
currentPath: computed(() => route.path),
270271
pluginConfigs: computed(() => appStore.themeConfig.plugins),
271-
enabledComment: computed(() => enabledCommentPlugin.value.plugin !== ''),
272+
enabledComment: computed(
273+
() => post.value.comments && enabledCommentPlugin.value.plugin !== ''
274+
),
272275
postStatsRef,
273276
SvgTypes,
274277
commonStore,

0 commit comments

Comments
 (0)