English
Appearance
Add comment functionality to your VitePress documentation site.
Comments allow readers to engage with your content, ask questions, and provide feedback. There are several popular comment systems you can integrate with VitePress.
Giscus is a comment system powered by GitHub Discussions. It's free, open source, and doesn't track users.
npm install @giscus/vue
Create a comment component:
<!-- .vitepress/theme/components/Comments.vue --> <template> <div class="comments"> <Giscus :repo="repo" :repo-id="repoId" :category="category" :category-id="categoryId" :mapping="mapping" :strict="strict" :reactions-enabled="reactionsEnabled" :emit-metadata="emitMetadata" :input-position="inputPosition" :theme="theme" :lang="lang" :loading="loading" /> </div> </template> <script setup> import Giscus from '@giscus/vue' import { useData } from 'vitepress' const { isDark } = useData() const repo = 'your-username/your-repo' const repoId = 'your-repo-id' const category = 'General' const categoryId = 'your-category-id' const mapping = 'pathname' const strict = '0' const reactionsEnabled = '1' const emitMetadata = '0' const inputPosition = 'bottom' const theme = computed(() => isDark.value ? 'dark' : 'light') const lang = 'en' const loading = 'lazy' </script> <style scoped> .comments { margin-top: 2rem; padding-top: 2rem; border-top: 1px solid var(--vp-c-divider); } </style>
Add comments to your theme layout:
<!-- .vitepress/theme/Layout.vue --> <template> <Layout> <template #doc-after> <Comments /> </template> </Layout> </template> <script setup> import DefaultTheme from 'vitepress/theme' import Comments from './components/Comments.vue' const { Layout } = DefaultTheme </script>
Gitalk is a modern comment component based on GitHub Issue and Preact.
npm install gitalk
<!-- .vitepress/theme/components/Gitalk.vue --> <template> <div id="gitalk-container"></div> </template> <script setup> import { onMounted } from 'vue' import { useRoute } from 'vitepress' import Gitalk from 'gitalk' import 'gitalk/dist/gitalk.css' const route = useRoute() onMounted(() => { const gitalk = new Gitalk({ clientID: 'your-client-id', clientSecret: 'your-client-secret', repo: 'your-repo', owner: 'your-username', admin: ['your-username'], id: route.path, distractionFreeMode: false }) gitalk.render('gitalk-container') }) </script>
Disqus is a popular hosted comment system.
npm install vue-disqus
<!-- .vitepress/theme/components/Disqus.vue --> <template> <div class="disqus-container"> <Disqus :shortname="shortname" :identifier="identifier" :url="url" /> </div> </template> <script setup> import { Disqus } from 'vue-disqus' import { useRoute, useData } from 'vitepress' const route = useRoute() const { site } = useData() const shortname = 'your-disqus-shortname' const identifier = route.path const url = `${site.value.base}${route.path}` </script>
Utterances is a lightweight comments widget built on GitHub issues.
<!-- .vitepress/theme/components/Utterances.vue --> <template> <div ref="utterancesRef" class="utterances-container"></div> </template> <script setup> import { ref, onMounted, watch } from 'vue' import { useData } from 'vitepress' const utterancesRef = ref() const { isDark } = useData() const createUtterances = () => { const script = document.createElement('script') script.src = 'https://utteranc.es/client.js' script.setAttribute('repo', 'your-username/your-repo') script.setAttribute('issue-term', 'pathname') script.setAttribute('theme', isDark.value ? 'github-dark' : 'github-light') script.setAttribute('crossorigin', 'anonymous') script.async = true utterancesRef.value.appendChild(script) } onMounted(() => { createUtterances() }) watch(isDark, () => { // Reload utterances when theme changes const iframe = utterancesRef.value.querySelector('iframe') if (iframe) { iframe.contentWindow.postMessage( { type: 'set-theme', theme: isDark.value ? 'github-dark' : 'github-light' }, 'https://utteranc.es' ) } }) </script>
Control comments per page using frontmatter:
--- comments: true ---
Create a wrapper component that handles different comment systems:
<!-- .vitepress/theme/components/CommentSystem.vue --> <template> <div v-if="showComments" class="comment-system"> <component :is="commentComponent" /> </div> </template> <script setup> import { computed } from 'vue' import { useData } from 'vitepress' import Giscus from './Giscus.vue' import Gitalk from './Gitalk.vue' import Disqus from './Disqus.vue' const { frontmatter, theme } = useData() const showComments = computed(() => { return frontmatter.value.comments !== false }) const commentComponent = computed(() => { const system = theme.value.commentSystem || 'giscus' switch (system) { case 'giscus': return Giscus case 'gitalk': return Gitalk case 'disqus': return Disqus default: return Giscus } }) </script>
Comments Plugin
Add comment functionality to your VitePress documentation site.
Overview
Comments allow readers to engage with your content, ask questions, and provide feedback. There are several popular comment systems you can integrate with VitePress.
Giscus
Giscus is a comment system powered by GitHub Discussions. It's free, open source, and doesn't track users.
Installation
Configuration
Usage
Create a comment component:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Integration
Add comments to your theme layout:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Gitalk
Gitalk is a modern comment component based on GitHub Issue and Preact.
Installation
Usage
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Disqus
Disqus is a popular hosted comment system.
Installation
Usage
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Utterances
Utterances is a lightweight comments widget built on GitHub issues.
Usage
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Configuration Options
Enable/Disable Comments
Control comments per page using frontmatter:
2
3
Custom Comment Component
Create a wrapper component that handles different comment systems:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Best Practices
Troubleshooting
Common Issues