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
}

有了这两文件就好了

相关推荐
子兮曰43 分钟前
CLI正在吞掉GUI:不是替代,是统治,AI时代的入口争夺战
人工智能·github·命令行
蚂蚁集团分布式架构3 小时前
🦐 不办 Meetup,开挑战赛!SOFAStack PR Challenge | SOFAStack 8 周年
后端·github·claude
逛逛GitHub4 小时前
13 万星的 GitHub 神器让 GLM-5.1 直接起飞,3 天烧了 1 亿 Token。
github
攀登的牵牛花5 小时前
本周 GitHub 趋势观察:为什么前端热榜越来越像“AI 工具市场”?
前端·github
第一程序员5 小时前
Python游戏开发:从入门到实践
python·github
殷紫川6 小时前
IDEA 集成 GitHub Copilot 指南:解锁 10 倍编码效率的全链路实战
github·intellij idea·github copilot
八号老王9 小时前
Google Cloud Vertex AI 接入 OpenClaw 记录
github
子兮曰9 小时前
同样做中文平台自动化:为什么你越跑越贵,而 OpenCLI 越跑越稳
前端·github·命令行
CoderJia程序员甲9 小时前
GitHub 热榜项目 - 日榜(2026-04-01)
人工智能·ai·大模型·github·ai教程
我先去打把游戏先10 小时前
Git 一个本地仓库同时推送到两个远程仓库(私人 GitHub + 公司 Git)保姆级教程
git·vscode·单片机·嵌入式硬件·物联网·学习·github