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
}

有了这两文件就好了

相关推荐
stereohomology23 分钟前
ChatGPT对我首个Github开源的MCP的点评
chatgpt·开源·github
xiaoliuliu123451 小时前
ArcGIS Pro 3.5.4专业桌面地理信息系统安装教程 Windows版:运行库+升级包+汉化补丁指南
github
_大学牲1 小时前
从零实现自己的agent第六期:Agent Team团队协作
github·agent·ai编程
_大学牲1 小时前
从零实现自己的agent第一期:什么是agent
github·agent·ai编程
_大学牲1 小时前
从零实现自己的agent第二期: 百行代码从零手搓agent
github·agent·ai编程
程序员柒叔2 小时前
OpenCode 一周动态-2026-W20
人工智能·github·copilot·agent·opencode
晚风_END2 小时前
Linux|操作系统|最新版zfs编译后的适用于centos7的rpm安装包完全离线安装介绍
linux·运维·服务器·c++·python·缓存·github
辰痕~2 小时前
使用GitHub管理代码
github
冴羽yayujs3 小时前
GitHub 前端热榜项目 - 日榜(2026-05-17)
前端·github
stereohomology4 小时前
DeepSeek对我首个Github开源项目mcp的点评
开源·github·mcp