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
}

有了这两文件就好了

相关推荐
海绵不是宝宝81712 小时前
连接远程服务器上的 jupyter notebook,解放本地电脑
服务器·jupyter·github
黑客飓风15 小时前
当GitHub宕机时,我们如何协作?
github·notepad++
mit6.82419 小时前
[Git] 如何拉取 GitHub 仓库的特定子目录
git·github
用户4665370150519 小时前
如何在 IntelliJ IDEA 中可视化压缩提交到生产分支
后端·github
用户4665370150519 小时前
git代码压缩合并
后端·github
若水晴空初如梦20 小时前
QT聊天项目DAY19
github
张较瘦_1 天前
[论文阅读] 人工智能 | 当Hugging Face遇上GitHub:预训练语言模型的跨平台同步难题与解决方案
论文阅读·人工智能·github
掘金安东尼1 天前
字节前端三面复盘:基础不花哨,代码要扎实(含高频题解)
前端·面试·github
寻月隐君1 天前
Rust Web 开发实战:使用 SQLx 连接 PostgreSQL 数据库
后端·rust·github
kymjs张涛1 天前
零一开源|前沿技术周刊 #12
ios·google·github