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
}

有了这两文件就好了

相关推荐
峰向AI5 小时前
119K Star 的 AI Agent 宝库:别人写好的 100 个模板,克隆就能跑
github
dong_junshuai5 小时前
每天一个开源项目#34 Desktop Commander:7.5K Star MCP 桌面工具箱
github
逛逛GitHub7 小时前
GitHub 上已开源,有人把《哈利·波特》中的笔记做出来了。
github
m0_738120728 小时前
PHP代码审计基础——面向对象(四)
android·开发语言·网络·安全·github·php
阿里嘎多学长8 小时前
2026-07-09 GitHub 热点项目精选
开发语言·程序员·github·代码托管
小帅不太帅10 小时前
我随手发了几张截图,白拿了一个月 AI 顶配会员
前端·github
程序员柒叔11 小时前
OpenCode 一周动态-2026-W28
人工智能·github·agent·opencode·hermes
Agent治理法学11 小时前
我开源了一套 AI Agent 框架:有性格、有规则、还会自己造工具
node.js·github
AI袋鼠帝11 小时前
开源WorkBuddy蓝皮书!从0到100最系统Agent实战指南~【建议收藏】
github·aigc
智脑API平台12 小时前
Codex Cloud 任务怎么用?GitHub 仓库、PR 审查和远程开发流程
github·codex·pr 审查