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
}

有了这两文件就好了

相关推荐
徐小夕35 分钟前
我用 AI 撸了个开源"万能预览器":浏览器直接打开 Office、CAD 和 3D 模型
前端·vue.js·github
码云之上4 小时前
从一个截图函数到一个 npm 包——pdf-snapshot 的诞生记
前端·node.js·github
阿祖zu5 小时前
内容创作 AI 透明化声明倡议与项目开源
前端·后端·github
AI成长日志5 小时前
【GitHub开源项目专栏】深度拆解:LangChain智能体系统架构设计与实现原理
langchain·开源·github
OPHKVPS9 小时前
WebRAT恶意软件借GitHub伪造漏洞利用程序传播
网络·安全·github
逛逛GitHub9 小时前
这个开源 skill 专门炼化你的离职同事。
github
逛逛GitHub10 小时前
Karpathy 开源了 Agent + Obsidian 个人知识库, 超级有启发。
github
zh_xuan12 小时前
Android Paging 3实现分页加载
android·git·github·paging 3
散峰而望13 小时前
【基础算法】动态规划从入门到进阶:记忆化搜索、线性 DP、LIS/LCS 一网打尽
c++·后端·算法·github·深度优先·动态规划·代理模式
CoderJia程序员甲13 小时前
GitHub 热榜项目 - 日榜(2026-04-06)
人工智能·ai·大模型·github·ai教程