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
}

有了这两文件就好了

相关推荐
逛逛GitHub16 分钟前
盘点 20 个 9 月份 GitHub 上顶顶顶的开源项目。
github
miofly21 分钟前
Google 发布 EmbeddingGemma 2:7.4 亿参数的多模态嵌入模型
开源·github
wflynn2 小时前
GitHub 今日推荐|lightcraft:纯 Rust 重写的 RAW 照片开发工具
rust·开源·github·lightroom·art·photography
wflynn2 小时前
GitHub 日榜趋势速报 | 2026-10-07
开源·github
孟陬3 小时前
#教程 dw, dm, dy, d18m 是何意?万物可 Badge | 定制漂亮精致小徽章,打造眼前一亮 README
npm·github
爱写代码的倒霉蛋3 小时前
新手如何借助agent改造github项目(保姆级教程)
github·新手友好·改造项目
u1301303 小时前
GitHub 热榜项目:日榜(2026-10-07)
驱动开发·github
高频因子挖掘机3 小时前
量化选股到底要不要每天拉全市场股票?从全市场扫描到候选池的行情数据设计
后端·github·api
miofly3 小时前
GitHub 日榜趋势速报 | 2026-10-08
开源·github
Skrrapper3 小时前
AI项目实战日记ep2:把 GitHub Issue 的第一轮脏活交给 AI:做一个 Issue 分诊助手
人工智能·github·issue