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
}

有了这两文件就好了

相关推荐
草梅友仁8 小时前
墨梅博客 1.9.0 发布与 LeanCloud 停服应对 | 2026 年第 11 周草梅周报
开源·github·ai编程
朱包林9 小时前
Python基础
linux·开发语言·ide·python·visualstudio·github·visual studio
sunny_13 小时前
📖 2026年 大厂前端面试手写题库已开源(2.3k star)
前端·面试·github
阿里嘎多学长16 小时前
2026-03-11 GitHub 热点项目精选
开发语言·程序员·github·代码托管
Yupureki16 小时前
《C++实战项目-高并发内存池》5.PageCache构造
c语言·开发语言·c++·单例模式·github
zhping101120 小时前
Linux 系统上使用 GitHub 加速工具
linux·运维·github
qiuyuyiyang1 天前
Nginx 反向代理之upstream模块以及完整配置反向代理示例
git·nginx·github
CoderJia程序员甲1 天前
GitHub 热榜项目 - 日榜(2026-03-14)
人工智能·ai·大模型·github·ai教程
猫头虎1 天前
如何解决openclaw安装skills报错command not foud:clawhub问题怎么解决?
langchain·开源·prompt·github·aigc·ai编程·内容运营
汪海游龙1 天前
03.15 AI 精选:Claude Opus/Sonnet 4.6 开放 100 万上下文
github·hacker news