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
}

有了这两文件就好了

相关推荐
weelinking9 小时前
【产品】00_产品经理用Claude实现产品系列介绍
数据库·人工智能·sql·数据挖掘·github·产品经理
Hommy8811 小时前
【剪映小助手】字幕信息生成接口
github·aigc·剪映小助手·视频剪辑自动化
用户07806253471918 小时前
纯前端实现 AI 抠图:我如何用 ONNX + Canvas 在浏览器里跑背景移除
github
白鲸开源18 小时前
干货!SeaTunnel(2.3.12)高阶用法(一):核心概念之数据流
java·大数据·github
逛逛GitHub18 小时前
Karpathy 加入 Anthropic 了,盘点他开源的 5 个硬核 GitHub 项目。
github
你的保护色18 小时前
RAID学习
github
ChampaignWolf19 小时前
GitHub Copilot 用于 SAP ABAP 在 VS Code 中:本地部署团队设置指南
github·copilot
VIV-19 小时前
Pycharm项目上传到Github
ide·pycharm·github
xG8XPvV5d19 小时前
GitHub Actions自动化部署全攻略
运维·自动化·github
ChampaignWolf21 小时前
GitHub 发布全新 Copilot 独立应用,正面硬刚 Claude Code 与 Codex
github·copilot