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
}

有了这两文件就好了

相关推荐
汤姆yu3 小时前
macOS系统下Aider完整安装、配置与实战使用教程
大数据·人工智能·算法·macos·github·copilot
小弥儿5 小时前
GitHub今日热榜 | 2026-07-04
学习·开源·github
CoderJia程序员甲6 小时前
GitHub 热榜项目 - 周榜(2026-07-04)
ai·大模型·llm·github
REDcker6 小时前
GitHub SSH 连接失败排障实录
运维·ssh·github
菜鸟是大神7 小时前
【Hermes入门11讲】第七讲:定时自动化——让Hermes成为你的24小时助手
人工智能·github·hermes
newbe365249 小时前
我们如何使用 impeccable 优化前端界面设计与实现稳定性
前端·人工智能·分布式·github·aigc·wpf
一次旅行15 小时前
AI 前沿日报 | 2026年7月3日 星期五
人工智能·github·ai编程
青山木19 小时前
快速搭建免费的个人博客网站:Hexo + GitHub Pages + Butterfly 完整指南
git·github
阿里嘎多学长1 天前
2026-07-03 GitHub 热点项目精选
开发语言·程序员·github·代码托管
江畔柳前堤1 天前
第11章:Docker 安全加固
运维·git·安全·docker·容器·eureka·github