教你使用Giscus在Vuepress2中开启评论功能

使用的插件: vuepress-plugin-comment2

环境: vuepress2

官网连接

点击下方链接进入官网
主页 | 评论插件 (vuepress-theme-hope.github.io)

Npm安装方式

npm i -D vuepress-plugin-comment2@next

Yarn安装方式

yarn add -D vuepress-plugin-comment2@next

Pnpm安装方式

pnpm add -D vuepress-plugin-comment2@next

Tip:Node的镜像见我文章:NPM的镜像源管理工具:NRM

设置Vuepress配置文件

Js

// .vuepress/config.js
const { commentPlugin } = require("vuepress-plugin-comment2");

module.exports = {
  plugins: [
    commentPlugin({
      // 插件选项
    }),
  ],
};

Ts

// .vuepress/config.ts
import { commentPlugin } from "vuepress-plugin-comment2";

export default {
  plugins: [
    commentPlugin({
      // 插件选项
    }),
  ],
};

Tip:config.js/ts目录如下

├─ docs
│  ├─ .vuepress
│  │  └─ config.js/ts
│  └─ README.md
├─ .gitignore
└─ package.json

使用Giscus

准备工作

  1. 你需要创建一个公开仓库,并开启评论区,以作为评论存放的地点

  2. 你需要安装 Giscus Appopen in new window,使其有权限访问对应仓库。

Tip:开启仓库的Disscussions
点击Settings
开启Discussions

  1. 在完成以上步骤后,请前往 Giscus 页面open in new window 获得你的设置。

只需要填写仓库和 Discussion 分类,之后滚动到页面下部的 “启用 giscus” 部分,获取 data-repo, data-repo-id, data-categorydata-category-id 这四个属性。

示例

示例

将记录下的四个值:data-repo, data-repo-id, data-categorydata-category-id 作为插件选项传入 repo, repoId, category categoryIdGiscus 配置

示例

const { commentPlugin } = require("vuepress-plugin-comment2");

module.exports = {
    ... // 省略Vuepress的配置
    ...
  plugins: [
    // vuepress-plugin-comment2评论与阅读量插件
    commentPlugin({
      // 插件选项
      provider: "Giscus", //评论服务提供者。
      comment: true, //启用评论功能
      repo: "Chengyunlai/Xxxx", //远程仓库
      repoId: "xxx", //对应自己的仓库Id
      category: "Announcements",
      categoryId: "xxx" //对应自己的分类Id
    }),
  ],
  ...
  ...
};

在Md文档中使用

此插件会全局注册评论组件 <CommentService />

所以在想放入评论组件的地方在Md文档中写上 <CommentService/>即可。

效果

效果

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值