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
}

有了这两文件就好了

相关推荐
Nautiluss2 小时前
一起玩XVF3800麦克风阵列(八)
大数据·人工智能·嵌入式硬件·github·音频·语音识别
uhakadotcom6 小时前
Python Protobuf 全面教程:常用 API 串联与实战指南
前端·面试·github
周杰伦_Jay7 小时前
【GOFrame】模块化框架与生产级实践
开发语言·gitlab·github
托马斯-酷涛12 小时前
加速GitHub加载速度-最终篇
github·proxy·代理
yuguo.im12 小时前
5 分钟快速入门 Github Actions
ci/cd·github·actions
阿里嘎多学长12 小时前
2025-12-12 GitHub 热点项目精选
开发语言·程序员·github·代码托管
gAlAxy...14 小时前
详解 Gitee/GitHub 中 HTTPS/SSH 方式数据库仓库创建与本地连接
https·gitee·github
测试人社区-小明15 小时前
AI在金融软件测试中的实践
人工智能·测试工具·金融·pycharm·机器人·github·量子计算
CoderJia程序员甲15 小时前
GitHub 热榜项目 - 日榜(2025-12-12)
ai·开源·大模型·github·ai教程
yuguo.im15 小时前
5 分钟快速入门 Gitlab CI/CD
ci/cd·gitlab·github