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
}

有了这两文件就好了

相关推荐
love530love30 分钟前
Windows 开源项目部署评估与决策清单(完整版)
人工智能·windows·python·开源·github
梦梦代码精1 小时前
开源即商用,预期产出、风险与优化建议
人工智能·gitee·前端框架·开源·github
AI成长日志3 小时前
【GitHub开源项目专栏】扩散模型开源项目深度解析:Stable Diffusion与ControlNet架构全景
stable diffusion·开源·github
SUNNY_SHUN3 小时前
ICLR 2026 | Judo: 7B小模型工业缺陷问答超越GPT-4o,用对比学习+强化学习注入领域知识
论文阅读·人工智能·学习·视觉检测·github
Vibelearning_AI4 小时前
Vibecoding进阶教程-从能用到可控(一):让coding agent也有自己的工具可用,减少不必要的重复工作
github
怪兽同学4 小时前
详解github workflows流
github
dadaobusi5 小时前
.gitignore配置问题
github
CoderJia程序员甲5 小时前
GitHub 热榜项目 - 日榜(2026-03-27)
人工智能·ai·大模型·github·ai教程
Carsene6 小时前
艺术化你的 Git 提交:类型与图标(全网最全)的实践准则
git·github
badhope7 小时前
10个GitHub高星开源项目推荐
大数据·人工智能·深度学习·数据挖掘·github