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
}

有了这两文件就好了

相关推荐
逛逛GitHub8 分钟前
GitHub 又一个 3D 人体可视化项目,AI 能力提升催生新场景。
github
峰向AI13 分钟前
多代理协作的正确姿势:Atlas让 Claude Code 和 Codex共享记忆
github
蜡台1 小时前
GitHub 关闭 Two‑factor authentication(2FA)
github
HaipengYu4 小时前
Star History 凉凉?5 分钟部署一套属于自己的 GitHub 星标统计服务
github
理智.6294 小时前
Git 工具使用之项目版本回退与修改备份:stash、reset、reflog 常用指令详解
git·gitee·github
尚雷55805 小时前
避坑指南:从零搭建 openGauss oGRAC 双节点集群,这些细节要注意
github·ograc
TunerT_TQ7 小时前
GitHub每日热评|用写HTML的方式生成确定性MP4:HeyGen开源的HyperFrames到底强在哪?
开源·github·资讯
楠楠子呀8 小时前
给 GitHub Pages 这类纯静态站加 WhatsApp 入口:三种不引后端的写法
github
lindd9119118 小时前
github项目Readme文档制作与远程推送(全自动化上传)
ai·github·ai的skill使用
毕竟是shy哥9 小时前
远程服务器使用github代理
github