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
}

有了这两文件就好了

相关推荐
数字游民952736 分钟前
网站备案全流程回放(腾讯云)
人工智能·git·github·腾讯云·网站备案·waytoopc
AI_567842 分钟前
零基础学Linux:21天从“命令小白”到独立部署服务器
linux·服务器·人工智能·github
不知疲倦的仄仄1 小时前
第五天:深度解密 Netty ByteBuf:高性能 IO 的基石
java·开源·github
Albert Edison1 小时前
【Git】多人协作一(同一分支下)
git·vscode·svn·github
系'辞5 小时前
【obsidian指南】配置obsidian git插件,实现obsidian数据定时同步到github仓库(Mac电脑)
macos·github·agent·知识库
草梅友仁13 小时前
墨梅博客 1.0.0 发布与更新 | 2026 年第 2 周草梅周报
github·ai编程·nuxt.js
周末程序猿14 小时前
杂谈|2025年总结
github
Controller-Inversion15 小时前
cdn协议
计算机网络·github
wzfj1234518 小时前
ssh 远程pc如何不用每次都输入密码
github
行百里er21 小时前
代码跑得慢?让Spring的StopWatch告诉你真相!
java·后端·github