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
}

有了这两文件就好了

相关推荐
zzqssliu7 小时前
煤炉自动代拍系统的队列设计与超时控制机制
git·github
fthux10 小时前
“装闭”,让装修套路“装”不下去
人工智能·ai·开源·github·open source
用户849137175471613 小时前
想做护眼工具却脑子一片空白?我用 OpenSpec 把模糊想法聊成了 v0.1
github·vibecoding
wangruofeng14 小时前
git-filter-repo 把 .git 从 112MB 砍到 1.4MB,但漏推 tag 让 clone 又胖回来
github·devops
峰向AI14 小时前
Block 放出大招!Buzz:一个中继统一代码、聊天、CI 全流程
github
dong_junshuai14 小时前
每天一个开源项目#47 4.4K Stars 的 LikeC4:让架构图随代码进化
github
独立开阀者_FwtCoder17 小时前
最近做了一个健身小程序:智形健身助手,健身的佬们来提点意见
前端·javascript·github
夕夕木各21 小时前
从第一个 PR 到 Vite 官方中文文档维护者
github·vite
隔窗听雨眠1 天前
GitHub Actions自动化运维实战:从零构建一体化CI/CD流水线
运维·自动化·github
dong_junshuai2 天前
每天一个开源项目#46 World Monitor:6.6万星、56层地图的全球情报中枢
github