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
}

有了这两文件就好了

相关推荐
小徐_23339 小时前
2025 前端开源三年,npm 发包卡我半天
前端·npm·github
落枫5913 小时前
如何快速搭建一个JAVA持续交付环境
后端·github
绝无仅有14 小时前
Git 操作偏门指南:常用和隐藏命令与问题解决
后端·面试·github
绝无仅有14 小时前
通过程序对接地图api展示旅游数据列表
后端·面试·github
掘金安东尼16 小时前
Vercel:我们为 React2Shell 发起了一项价值 100 万美元的黑客挑战
前端·javascript·github
掘金安东尼16 小时前
浏览器处理Base64数据的速度有多快?
前端·javascript·github
掘金安东尼16 小时前
为不同场景设计多样化的页面过渡动画
前端·javascript·github
猴子年华、16 小时前
【每日一技】:GitHub 精确查询
开发语言·python·github
信鸽爱好者16 小时前
Windows +VM虚拟机安装github服务器
服务器·windows·ubuntu·机器人·github
无限大617 小时前
为什么"容器化"技术很重要?——从虚拟机到 Docker
后端·github