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
}

有了这两文件就好了

相关推荐
粥里有勺糖9 小时前
视野修炼-技术周刊第138期 | 不要让 AI 代表你
前端·github·aigc
小帅不太帅10 小时前
Gemini 4 很顺手,但 agy CLI 看不见上下文和额度,我做了个开源状态栏
github·agent
一条Go12 小时前
ent + PostgreSQL:部分唯一索引怎么表达「全表最多一个」
后端·github
一条Go12 小时前
开源新生代雷达 · 第 21 期
github
wflynn13 小时前
GitHub 今日推荐|xcl:在 Windows PC 上直接运行 Xbox Series X|S 游戏
rust·开源·github·d3d12·gdk·rdna2
逛逛GitHub14 小时前
本周 TOP 11 排名的 GitHub 开源项目大盘点,看看能用到哪些。
github
用户693717500138415 小时前
AI 用久了,我发现自己越来越不想找人聊天了
前端·后端·github
怕浪猫1 天前
NVIDIA 全产品谱系与演进
javascript·面试·github
一条Go1 天前
Grafana 面板嵌入:为什么 kiosk 必须是「裸参数」
后端·github
一条Go1 天前
开源新生代雷达 · 第 20 期
github