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
}

有了这两文件就好了

相关推荐
秋千易9 小时前
同一提交,旧基线红、新基线绿:基线放行了门禁
github
撸码猿15 小时前
1Password 后端被入侵:密码库为什么没被拿走
网络安全·github·供应链安全·钓鱼·1password
一条Go15 小时前
26 篇之后:Alioth 的 26 个设计决定
后端·github
一条Go15 小时前
开源新生代雷达 · 第 25 期
github
钱栈up19 小时前
GitHub热榜上手|Claude Code Game Studios:49个AI代理的独立游戏工作室
开源·github·shell
wflynn2 天前
GitHub 日榜趋势速报 | 2026-11-27
开源·github
一条Go2 天前
全链路 e2e:一次跑出 20 个现象,收敛成 5 个根因
后端·github·测试
一条Go2 天前
开源新生代雷达 · 第 24 期
github
钱栈up2 天前
GitHub 热榜上手|anthropics/skills:18.9万星的 Claude 技能库
python·开源·github
李永奉2 天前
Git和GitHub-VS Code 图形化 Git 放弃更改、暂存与取消暂存、撤销上一次提交(VS Code 界面操作 + 命令行对照)
git·github