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
}

有了这两文件就好了

相关推荐
MicrosoftReactor4 小时前
技术速递|GitHub Copilot CLI:快速上手指南
github·copilot
蜜汁小强5 小时前
Github 账号与登录 2025
github
Sahadev_6 小时前
GitHub 一周热门项目速览
github
CoderJia程序员甲6 小时前
GitHub 热榜项目 - 日榜(2025-11-24)
ai·开源·llm·github·ai教程
4***V20213 小时前
GitLab Pages配置
git·gitlab·github
whysqwhw17 小时前
BaseObject 及其子类的完整继承关系 ASCII 树
github
r***d86518 小时前
GitHub星标15万+的Docker项目,使用指南
docker·容器·github
sulikey20 小时前
从入门到精通:如何自己编写高质量的 .gitignore(面向工程实践)
git·gitee·编辑器·gitlab·github·gitignore·gitattributes
散峰而望20 小时前
C++数组(一)(算法竞赛)
c语言·开发语言·c++·算法·github
SelectDB1 天前
压缩率提升 48%,详解 Apache Doris 存储压缩优化之道|Deep Dive
数据库·开源·github