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
}

有了这两文件就好了

相关推荐
OpenTiny社区4 小时前
TinyEngine 2.11版本发布:AI 进一步融入画布,Vue 工程可一键转DSL
前端·vue.js·github
七牛开发者6 小时前
RAG 工程里的上下文剪枝:如何减少 68% 的上下文
前端·css·github
Alex66302811 小时前
我重写了 Hermes Agent,专门修掉了它的 4 个硬伤
github
考虑考虑11 小时前
git中的tag
git·gitlab·github
小墨同学boy12 小时前
WorkBuddy零基础教程进阶篇
人工智能·github·aigc
BerrySen17813 小时前
GitHub开源项目破圈方法论:从技术自嗨到生态共赢
开源·github
JavaGuide1 天前
一个神级 PR Review Agent 诞生了:读 diff、写总结、找风险全自动!
github·ai编程
逛逛GitHub1 天前
1.3 万人点赞的 GitHub 项目,让 AI Agent 操作 Office 文件。
github
OpenTiny社区1 天前
Skill 设计:封装、评测、运营,一次讲透
前端·github