Please wait...

小波Note

四川 · 成都市11 ℃
English

Comment system using GitHub Discussions in Nuxt

成都 (cheng du)9/11/2024, 1:16:18 PM2.54kEstimated reading time 8 minFavoriteCtrl + D / ⌘ + D
cover
IT FB(up 主)
Back-end development engineer
Article summary
Github Copilot

Loading article summary...

How it works

When giscus loads, it uses the GitHub Discussions search API to find a discussion associated with the current page based on the selected mapping method (e.g., URL, pathname, title, etc.). If no matching discussion is found, the giscus bot will automatically create a discussion the first time someone leaves a comment or reaction.

Visitors who want to comment must authorize the giscus app to post on their behalf via the GitHub OAuth flow, or they can comment directly in the GitHub Discussion. You can manage comments on GitHub.

Enabling GitHub Discussions

  1. Create a public repository and enable the Discussions feature in the repository's Settings -> Options -> Features.

discussion

  1. Create a new category in the repository's Discussions page to store comments.

discussion edit

discussion category

Installing Giscus in GitHub Apps

Visit the link giscus app, click Install, select your repository, and install the Giscus App.

Configuring Giscus

Configure it on the giscus config website

Fill in the following information in sequence:

  • Repository name
  • mapping of pages and comments (I can't choose pathname because I have multiple languages, otherwise there will be multiple comment themes such as /xxx, /en/xxx, /ja/xxx)
  • Repository category

giscus config

Then copy this code

giscus code

Installing in nuxt

bash
        npm install @giscus/vue

    
package.json
        "devDependencies": {
    "@giscus/vue": "^3.0.0"
}

    
xxx.vue
        <script setup lang="ts">
import Giscus from '@giscus/vue'
import 'giscus';
</script>

<template>
    <Giscus
        id="comments"
        repo="it-fb/it-fb-comment"
        repoid="xxx"
        category="Comment"
        categoryid="xxx"
        mapping="specific"
        :term="blog"
        reactionsenabled="1"
        emitmetadata="0"
        inputposition="top"
        :theme="color.value"
        :lang="locale === 'zh' ? 'zh-CN' : locale"
        loading="lazy"
    />
</template>