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
}

有了这两文件就好了

相关推荐
Yingyingyingyyy4 分钟前
GitHub 开源热榜项目-周榜(2026-11-02)
人工智能·开源·github
OpenTiny社区17 分钟前
AI 生成的 Vue 代码,终于能直接用了!
前端·vue.js·github
饭后一颗花生米37 分钟前
GitHub Actions 自动化:5 个真实运维提效案例
运维·自动化·github
狂师1 小时前
GitHub 上最值得装的 8 个 Agent Skill 仓库,亲测好用!
程序员·github·ai编程
miofly2 小时前
GitHub 日榜趋势速报 | 2026-11-03
开源·github
椒哥14 小时前
一天被问几十次"允许",我统计了 517 次,然后写了个插件
前端·javascript·github
一点一木15 小时前
🚀 2026 年 10 月 GitHub 十大热门项目排行榜 🔥
人工智能·github
WANGXIN56716 小时前
攻克微信读书 Web 端「漏抓 40% 内容」顽疾:我开源了一个全书无损导出精排 PDF / EPUB / Markdown 工具
github
dong_junshuai16 小时前
每天一个开源项目#131 nvm:切换 Node 的关键在当前 Shell
github
miofly17 小时前
Mistral Large 4发布,万亿参数模型的编码与安全实测数据
开源·github