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
}

有了这两文件就好了

相关推荐
王二麻子6661 小时前
Ctrl+V 粘贴截图,Claude Code + DeepSeek 直接烂对话?这个开源项目把坑填了
github
用户938515635072 小时前
手把手教你用 Git 管理代码:从单机到分布式,再也不怕硬盘坏了
github
難釋懷2 小时前
Nginx虚拟主机
git·nginx·github
moMo3 小时前
# Git 入门—代码仓库的使用
git·github
IceSugarJJ3 小时前
Open-AutoGLM项目学习
语言模型·微信小程序·github
阿里嘎多学长4 小时前
2026-05-22 GitHub 热点项目精选
开发语言·程序员·github·代码托管
Dontla5 小时前
Github创建项目(创建仓库、新建项目、新建仓库)步骤
github
放下华子我只抽RuiKe55 小时前
React 从入门到生产(七):性能优化实战
前端·javascript·人工智能·react.js·性能优化·前端框架·github
晓杰'5 小时前
Balatro后端进阶(2):基于GitHub Actions的CI自动化验证实现
websocket·ci/cd·typescript·node.js·自动化·github·nestjs
析数塔6 小时前
Codegraph 实战:用知识图谱让 AI 编程效率翻倍
人工智能·github