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
}

有了这两文件就好了

相关推荐
u1301303 小时前
GitHub 热榜项目:日榜(2026-10-21)
人工智能·github
逛逛GitHub5 小时前
盘点本周 11 个 Star 攀升最多的 GitHub 开源项目。
github
蒲公英内测分发6 小时前
智能门锁量产时,工厂测试 App 一直在更新,产线怎么避免装错 APK?
服务器·人工智能·github·智能硬件·智能手表
本地化文档7 小时前
llvm-libc-docs-l10n
c语言·github·gitcode·sphinx·llvm·crowdin
wflynn7 小时前
GitHub 日榜趋势速报 | 2026-10-21
开源·github
钱栈up8 小时前
GitHub热榜上手|Claude插件:4.3万星官方目录
python·开源·github
大狼鲸9 小时前
阿里云ECS自动快照怎么配置?新手数据备份避坑指南
阿里云·云计算·github
wflynn9 小时前
GitHub 日榜趋势速报 | 2026-10-19
开源·github
高频因子挖掘机9 小时前
A股量化第一步:如何利用 QuantDash 实现日K数据清洗、前复权校验与缺失值处理
后端·github·api
miofly11 小时前
GitHub 今日推荐|pandacode:本地桌面统一管理多个AI编码代理
rust·开源·github