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
}

有了这两文件就好了

相关推荐
csdn小瓯1 小时前
CI/CD流水线搭建:GitHub Actions + Docker + Railway自动化部署实战
ci/cd·docker·github
不做无法实现的梦~1 小时前
Git 新手到团队协作与 GitHub/GitCode 指南
git·github·gitcode
亦暖筑序2 小时前
Vibe Coding 用久了,代码手感真的会退化——以及我怎么试图解决这个问题
程序员·开源·github
谷哥的小弟2 小时前
(最新版)Git&GitHub实操图文详解教程(02)—安装Git
git·github·安装·配置·下载·图文教程
谷哥的小弟2 小时前
(最新版)Git&GitHub实操图文详解教程(01)—Git的起源
git·github
小此方3 小时前
Re:Linux系统篇(十四)工具篇 · 五:Git 高效协作实战与“三板斧”秘籍
linux·git·github
Pan Zonghui3 小时前
GitHub Bug反馈与修复全流程指南
github·bug
2401_8734794012 小时前
运营活动被薅羊毛怎么防?用IP查询+设备指纹联动封堵漏洞
java·网络·tcp/ip·github
哆哆啦0016 小时前
使用 Obsidian + GitHub Actions + GitHub Pages 搭建内容发布流
数据库·笔记·github·obsidian