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
}

有了这两文件就好了

相关推荐
保卫大狮兄16 分钟前
2小时,我搭了一套仓库出入库管理系统:收货、领料、退料、库存全打通!
wms·github·仓库·入库
沙蒿同学42 分钟前
不引 Ghostscript:我用纯 Go 给 PDF 做了一场「压缩手术」
前端·后端·github
wflynn6 小时前
GitHub 日榜趋势速报 | 2026-10-23
开源·github
miofly7 小时前
Anthropic开源MHS标准,让AI智能体直接操作实验室硬件
开源·github
m4Rk_8 小时前
【论文阅读】Agent记忆机制(109):MemComposer——用强化学习学会选哪些记忆、选多少以及怎样排序
论文阅读·人工智能·学习·开源·github
Orange Wu9 小时前
GitHub SSH 443 端口配置解决连接失败
github
左手吻左脸。9 小时前
新环境配置git
github
miofly9 小时前
GitHub 今日推荐|dquickts:能暂停、能存档的 QuickJS
开源·github
import_random9 小时前
[git]只有git,没有github, 如何工作
git·github
import_random9 小时前
[git]先创建远程仓库or先创建本地项目
git·github