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
}

有了这两文件就好了

相关推荐
ssshooter7 小时前
彻底搞懂 SSH 与 Git 的“幕后交易”
git·github·全栈
irisMoon068 小时前
GitHub Copilot
github·copilot
消防大队VUE支队13 小时前
家里到底连了多少设备?这款开源神器让你一目了然
github
逛逛GitHub14 小时前
9 个 超绝的 AI 控制电脑 GitHub 开源项目。
github
QC七哥17 小时前
伪造git提交记录生成点阵字符
git·github
TimberWill17 小时前
GitHub Copilot 一键生成中文commit提示语规则设置
git·github
徐小夕18 小时前
pxcharts 多维表格开源!一款专为开发者和数据分析师打造的轻量化智能表格
前端·架构·github
NocoBase19 小时前
GitHub 上星星数量前 10 的 AI CRM 开源项目
人工智能·低代码·开源·github·无代码
CoderJia程序员甲20 小时前
GitHub 热榜项目 - 日榜(2025-12-22)
ai·开源·大模型·github·ai教程
cnnews21 小时前
某讯T1刷armbian
linux·ubuntu·开源·github