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
}

有了这两文件就好了

相关推荐
我命由我1234513 小时前
Git 推送报错:error: src refspec main does not match any
运维·git·gitee·github·运维开发·学习方法·版本控制
阿里嘎多学长14 小时前
2026-09-20 GitHub 热点项目精选
开发语言·程序员·github·代码托管
峰向AI15 小时前
skill-up: [阿里开源] 让 AI Agent Skills 自己进化的评估工具
github
子林super19 小时前
顺序表用Python3定义与增删改查
github
子林super19 小时前
Python非空判断与类型检查写法
github
子林super19 小时前
Python list与array关键区别及使用场景
github
子林super19 小时前
Python中None与null的区别
github
u13013021 小时前
GitHub 热榜项目:周榜(2026-09-20)
人工智能·github
u1301301 天前
GitHub 热榜项目:日榜(2026-09-20)
人工智能·github
逛逛GitHub1 天前
外网 3500 万人围观的 Jev 模型,有这 10 个神奇玩法。
github