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 小时前
GitHub Actions自动化运维实战:从CI/CD到云原生部署
运维·自动化·github
官乐11 小时前
如何去创建Github仓库
github
码流怪侠15 小时前
【GitHub】WorldMonitor:一个工程极致主义的实时全球情报仪表盘深度解析
github
北极糊的狐19 小时前
20.3 使用 Vercel CLI 手动部署(无需 GitHub,适合不常更新的项目)
github
2401_8534482320 小时前
Git安装流程和基础使用步骤
git·github
官乐20 小时前
Prompt推荐:如何写一个好的Github README.md
prompt·github
官乐20 小时前
Github创建上传仓库流程
github
tokenKe21 小时前
Buzz:蜂巢意识协作平台|Agent 不是 Bot,而是持有独立密钥对的团队成员|SSP Github Daily
github
zdkdchao1 天前
建立gitee对github仓库的镜像
gitee·github
小弥儿1 天前
GitHub 今日热榜 | 2026-07-24:金融 K 线基础模型上榜
学习·金融·开源·github