vitepress搭建的博客系统cdn引入github discussions评论系统

github仓库必须是公开的。

按照CDN的方式引入

打开discussions模块

安装giscus app


配置giscus

就是刚安装了giscus app的仓库

页面往下走,生成了代码:

配置vitepress

采用了CDN的方式引入

使用web component

随便找个地方试试组件

效果

有了

优化

那么多页面,一个一个的添加评论组件不现实。封装个评论组件覆盖原来的vitepress layout

  1. 在.vitepress目录下的theme目录下创建组件
html 复制代码
<!-- Layout.vue -->
<template>
  <Layout>
    <template #doc-after>
      <giscus-widget
        id="comments"
        repo="chergn/questions"
        repoid=""
        category="Announcements"
        categoryid=""
        mapping="title"
        term="Welcome to giscus!"
        reactionsenabled="1"
        emitmetadata="0"
        inputposition="top"
        theme="light"
        lang="en"
        loading="lazy"
      ></giscus-widget>
    </template>
  </Layout>
</template>

<script lang="ts" setup>
import DefaultTheme from "vitepress/theme";
const { Layout } = DefaultTheme;
</script>
  1. 在.vitepress目录下的theme目录下的index.js文件配置layout
javascript 复制代码
import DefaultTheme from 'vitepress/theme'
import CommentLayout from './CommentLayout.vue'

export default {
  extends: DefaultTheme,
  // 使用注入插槽的包装组件覆盖 Layout
  Layout: CommentLayout
}

有了这两文件就好了

相关推荐
七牛云行业应用1 小时前
Jev 报 401 / api_key_required 怎么解决:TypeSafe AI 官方错误码表与排查步骤
算法·github
誰能久伴不乏2 小时前
保姆级 GitHub 协作教程
github
miofly8 小时前
Claude 自主发现类 CRISPR 结构的新型逆转录酶系统:Anthropic 生命科学实验室的早期成果
开源·github
HelloGitHub10 小时前
《HelloGitHub》第 126 期
开源·github
miofly10 小时前
GitHub 日榜趋势速报 | 2026-09-28
开源·github
miofly15 小时前
GitHub 日榜趋势速报 | 2026-09-27
开源·github
怕浪猫15 小时前
顶级模型一句话,AI 写出了能玩的 QQ飞车
前端·面试·github
粥里有勺糖15 小时前
视野修炼-技术周刊第134期 | 豆豆眼头像
前端·github·aigc
粥里有勺糖16 小时前
体验一下最近比较🔥的闪卡SKILL
前端·github
miofly16 小时前
GitHub 日榜趋势速报 | 2026-09-26
开源·github