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
}

有了这两文件就好了

相关推荐
cws2004012 小时前
MFA双因素用户使用手册
运维·windows·网络安全·github·邮件·邮箱
无限进步_6 小时前
二叉搜索树(BST)详解:从原理到实现
开发语言·数据结构·c++·ide·后端·github·visual studio
大强同学7 小时前
CloudFlare-ImgBed+HuggingFace图床搭建教程
windows·github·图床搭建
T_Fire_of_Square8 小时前
crewai的进一步工具扩展
python·github
明洞日记9 小时前
【软考每日一练015】计算机网络:DNS 递归查询与迭代查询解析
git·计算机网络·github
无限进步_1 天前
【C++】大数相加算法详解:从字符串加法到内存布局的思考
开发语言·c++·windows·git·算法·github·visual studio
烟锁池塘柳01 天前
GitHub 强制回退版本并覆盖远程仓库
git·github
Maggie_ssss_supp1 天前
Linux-MySQL主从复制
github
cg50171 天前
Continue插件实现本地部署一个“cursor”或“github copilot”
github·copilot·curcor
妙娲种子1 天前
gittee连接github镜像
gitee·github