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
}

有了这两文件就好了

相关推荐
L_Xian20 分钟前
StarrySky重新维护了,摆烂了一段时间,想想还是搞搞吧。
android·github·音视频开发
风起时Funchs20 分钟前
我把 JetBrains 的 Git 客户端搬到了 VS Code
github
神奇椰子39 分钟前
基于浪浪云轻量服务器与宝塔面板的CMS快速部署实践
运维·服务器·github
冴羽yayujs1 小时前
GitHub 热门项目-日榜(2026-05-13)
github
0vvv02 小时前
github拆分小批量上传文件
github
乐动心情2 小时前
RocksDB的代码分析报告
github
知识领航员13 小时前
蘑兔AI音乐深度实测:功能拆解、实测表现与适用场景
java·c语言·c++·人工智能·python·算法·github
morestrive16 小时前
基于 fabric.js 实现浏览器端矢量 PDF 导出
前端·github
右耳朵猫AI20 小时前
GitHub Trending 本周 Top 10
github
AlexMaybeBot20 小时前
巧用 OpenClaw 为 Android 开发电脑瘦身
android·github·ai编程