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
}

有了这两文件就好了

相关推荐
wflynn14 小时前
GitHub 日榜趋势速报 | 2026-11-27
开源·github
一条Go15 小时前
全链路 e2e:一次跑出 20 个现象,收敛成 5 个根因
后端·github·测试
一条Go15 小时前
开源新生代雷达 · 第 24 期
github
钱栈up19 小时前
GitHub 热榜上手|anthropics/skills:18.9万星的 Claude 技能库
python·开源·github
李永奉1 天前
Git和GitHub-VS Code 图形化 Git 放弃更改、暂存与取消暂存、撤销上一次提交(VS Code 界面操作 + 命令行对照)
git·github
TunerT_TQ1 天前
【开源 L3 静态取证|工程评测】xnulinux:双内核实验——可复现的环境与许可比截图更重要
github
一条Go1 天前
proto 契约:校验注解、错误码与「文案即接口」
后端·github
一条Go1 天前
15 套品牌色 + 双模式:把颜色关进三层 token
前端·github
逛逛GitHub1 天前
GitHub 上 1.6 万 Star!这个 GitHub 项目让 AI 帮你复刻视频
github
秋千易2 天前
Agent 用不了 Skill,卡在 5 个断点
github