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
}

有了这两文件就好了

相关推荐
DogDaoDao41 分钟前
【GitHub】CodeGraph 深度解析:为 AI 编程代理构建预索引代码知识图谱
人工智能·程序员·github·知识图谱·ai编程·ai agent·codegraph
疋瓞41 分钟前
G内使用github实践方式
github
2601_961194021 小时前
高中英语教资资料推荐|科三大题背诵和教学设计模板
git·开源·github·开源软件·开源协议·ossinsight
程序猿阿伟1 小时前
《扣子如何让OpenClaw技能开发提速》
人工智能·git·github
_codemonster2 小时前
GitHub 删除或私有化远程仓库(Repository)教程
github
微软技术栈2 小时前
技术速递|面向初学者的 GitHub Copilot CLI:交互模式与非交互模式
人工智能·github·copilot
Hommy882 小时前
【开源剪映小助手】架构设计
开源·github·aigc·剪映小助手·视频剪辑自动化
yyuuuzz3 小时前
谷歌云基础服务的入门认知
linux·运维·服务器·数据库·人工智能·github
咖啡星人k4 小时前
MonkeyCode vs Replit vs GitHub Codespaces:云端开发环境终极对比
github
tealcwu4 小时前
【Git 实战】三类方案实现一键推送多端仓库(Gitee & GitHub)
git·gitee·github