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
}

有了这两文件就好了

相关推荐
UVM_ERROR24 分钟前
RDMA Scheduler + TX + Completion RTL 开发经验分享
笔记·vscode·ssh·github·芯片
Salt_072832 分钟前
DAY 36 官方文档的阅读
python·算法·机器学习·github
粟悟饭&龟波功2 小时前
【GitHub热门项目精选】(2025-12-19)
前端·人工智能·后端·github
天勤量化大唯粉3 小时前
枢轴点反转策略在铜期货中的量化应用指南(附天勤量化代码)
ide·python·算法·机器学习·github·开源软件·程序员创富
CoderJia程序员甲3 小时前
GitHub 热榜项目 - 日榜(2025-12-19)
ai·开源·llm·github
小明_GLC4 小时前
关于Pycharm中导入github项目,出现依赖包报错
github
张小九997 小时前
fpocket安装和使用教程
linux·机器学习·github
charlee448 小时前
Github项目CI&CD部署
ci/cd·github·devops·github actions
知行力9 小时前
【GitHub每日速递 20251219】Claude-Mem:持久内存压缩系统,为Claude Code带来上下文连续性新体验!
github
薛定e的猫咪9 小时前
覆盖文献到写作全流程!GPT-Academic 多模型学术助手安装与使用指南
人工智能·gpt·github