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
}

有了这两文件就好了

相关推荐
葟雪儿1 分钟前
本地项目上传到GitHub(小白篇)
git·github
HelloGitHub27 分钟前
《HelloGitHub》第 125 期
开源·github
苏灿烤鱼34 分钟前
一个用 Nim 写的隐私优先 Twitter 替代前端,源码级技术剖析
后端·github·twitter
秋风点枝1 小时前
第二篇:安装 Argo CD + 第一次部署应用
kubernetes·github·argocd
星云API技术支持1 小时前
企业微信二次开发:控制台回调预览与服务器Webhook如何配合
服务器·github·企业微信
小弥儿13 小时前
GitHub今日热榜 | 2026-08-26:AI 大脑与知识管理扎堆
人工智能·学习·开源·github
阿里嘎多学长14 小时前
2026-08-24 GitHub 热点项目精选
开发语言·程序员·github·代码托管
其实防守也摸鱼14 小时前
信创是什么:一文读懂信息技术应用创新
人工智能·阿里云·云计算·github·copilot
秃秃秃秃哇15 小时前
fatal: the remote end hung up unexpectedl
github
峰向AI15 小时前
Label Studio:数据标注领域的"瑞士军刀",文本、音频、视频、图片、时序全部拿捏
github