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
}

有了这两文件就好了

相关推荐
Jinkxs2 小时前
告别996:GitHub Copilot将我的开发效率提升300%的实战记录
github·copilot
第一程序员6 小时前
Python与区块链:非科班转码者的指南
python·github
阿琳a_11 小时前
在github上部署个人的vitepress文档网站
前端·vue.js·github·网站搭建·cesium
wuxuand14 小时前
GitHub页面配置
github
darkb1rd14 小时前
claurst:Rust 重构终端编码代理实战指南
开源·github·好物分享
小雨青年14 小时前
当缓存成为生产力:GitHub Actions 缓存机制的深度优化指南
缓存·github
SUNNY_SHUN14 小时前
LiveKit Agents:基于WebRTC的实时语音视频AI Agent框架(9.9k Star)
人工智能·github·webrtc
CoderJia程序员甲15 小时前
GitHub 热榜项目 - 日榜(2026-04-03)
人工智能·ai·大模型·github·ai教程
AI成长日志15 小时前
【GitHub开源项目】Harness CI/CD平台深度解析:架构设计、核心功能与实战指南
ci/cd·开源·github