Core's ink

Back

Comment System

Giscus comments backed by GitHub Discussions

Giscus Comment System#

Setup#

  1. Enable Discussions in the public GitHub repository.
  2. Install the giscus app ↗ on that repository.
  3. Create a discussion category, for example Comments.
  4. Open giscus.app ↗, choose the repository and category, then copy data-repo-id and data-category-id.
  5. Fill them into src/site.config.ts:
src/site.config.ts
export const integ: IntegrationUserConfig = {
  // ...
  giscus: {
    enable: true,
    repo: 'owner/repo',
    repoId: 'R_...',
    category: 'Announcements',
    categoryId: 'DIC_...',
    mapping: 'pathname',
    strict: '0',
    reactionsEnabled: '1',
    inputPosition: 'bottom',
    theme: 'preferred_color_scheme',
    lang: 'zh-CN'
  }
}
ts

Mapping#

Use mapping: 'pathname'. Each article is identified by its URL pathname, so the domain can change without losing the discussion mapping.

Usage#

The layouts already render the component:

import Giscus from '@/components/comments/Giscus.astro'

<Giscus />
astro

It is enabled per post through the comment: true frontmatter field.