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
}

有了这两文件就好了

相关推荐
懒人82 小时前
本地配置推送至GitHub远程仓库
github
SL_staff2 小时前
APS降本增效的关键:在JVS中实现‘人-机-料-法-环’全要素耦合调度
java·github·全栈
chingho3 小时前
GitHub上这10个C#项目,不仅实用,还怪好玩的
c#·github·.net·开源项目
miofly3 小时前
Codex CLI 0.157.0 自动启动守护进程引发用户争议
开源·github
QuantiCore_IO3 小时前
量化回测复权数据的工程实践:从 API 获取到数据质量验证
后端·github·api
miofly3 小时前
Cursor 用 S3 上的 WAL 替代副本协调,Push 吞吐量超过每秒 300 次
开源·github
逛逛GitHub4 小时前
5 个 GitHub 上开源的稀奇古怪小玩意儿,这一届网友真天才。
github
u1301304 小时前
GitHub 热榜项目:日榜(2026-10-12)
人工智能·github
Ken_P_##5 小时前
WordAgent
github·agent
u1301305 小时前
GitHub 热榜项目:日榜(2026-10-11)
人工智能·github