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
}

有了这两文件就好了

相关推荐
wangruofeng1 小时前
11 万 Star 的生成式 AI 入门课,Microsoft 做对了什么
github·aigc·ai编程
峰向AI2 小时前
Agent 看不了视频?这个 7K Star 的开源插件一招搞定
github
程序员吕洞宾2 小时前
开源多维表格SmartTable V1.6:自动化工作流,把重复操作交给系统即可
开源·自动化·github·多维表格·飞书多维表
zqx_72 小时前
【无标题】
github
FreeBuf_3 小时前
公开GitHub Issue可诱骗AI泄露私有数据,绕过防护仅需一词
人工智能·github·issue
JavaGuide4 小时前
又一个画图 Skill 开源,再见手动画 draw.io!
前端·后端·github
小弥儿4 小时前
GitHub今日热榜 | 2026-07-09:OfficeCLI 以 92% 日增幅入围
学习·开源·github
逛逛GitHub5 小时前
GitHub 上 5 个小众但实用的开源项目,感兴趣收藏一波。
github
逛逛GitHub5 小时前
4 个最近值得收藏的 GitHub 开源项目。
github
粤M温同学7 小时前
VS Code GitHub Copilot插件中配置 DeepSeek 模型
github·copilot