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
}

有了这两文件就好了

相关推荐
码上农民4 小时前
微信样式下载
github
破烂pan13 小时前
github下载repo中的单独文件
github
SelectDB16 小时前
Doris MCP Server v0.6.0 正式发布
github
Solyn_HAN20 小时前
GitHub 系统全面详细使用指南
github
逛逛GitHub1 天前
13 个优质的 GitHub 项目,哪个你用过?
github
spionbo1 天前
.NET Framework 3.5 安装错误0x80070002、0x800F081F、0x80004002、0x800F09
github
JEECG低代码平台1 天前
【2025/11】GitHub本月热度排名前十的开源Java项目
java·开源·github
( ˶˙⚇˙˶ )୨⚑︎1 天前
VSCode SSH免密连接主机 GitHub添加SSH密钥
vscode·ssh·github
crossoverJie1 天前
Git cherry-pick 使用小技巧
git·github
吃饺子不吃馅1 天前
面试过别人后,我对面试祛魅了
前端·面试·github