• vuepress2.x集成评论插件


    这是官方文档

    这是效果

    开通Giscus

    Giscus是github的一个功能,用了专门存放评论的功能。需要依托一个仓库。
    我这里就拿我这个当前vuepress项目开开通。
    Settings>Features>Discussions

    获取Giscus信息

    进入此网站,获取信息

    在你的vuepress项目中启用此插件

    yarn add -D vuepress-plugin-comment2@next
    

    my-book/docs/.vuepress/config.js

    plugins: [
        ...
        commentPlugin({
          provider: "Giscus",
          repo: "dshvv/red-treasure-book",
          repoId: "MDEwOlJlcG9zaXRvcnk0MDcxNDYxODA=",
          category: "Announcements",
          categoryId: "DIC_kwDOGESOxM4CPs5U",
        })
    ]
    

    配置和应用主题

    此插件需要自己全局注册评论组件
    推荐将评论组件 () 插入在 组件后。
    所以我们需要使用一个主题来完成这些(vuepress2 已经不提供暴漏layout组件了,所以只能如此)

    创建一个主题
    在my-book/docs/.vuepress下创建如下目录结构

    .vuepress
     |--index.js
     |--layout
        |--index.vue
    

    index.js

    const { path } = require('@vuepress/utils');
    const { defaultTheme } = require("@vuepress/theme-default");
    
    module.exports.commentTheme = options => ({
      name: "comment-theme",
    
      // we are extending @vuepress/theme-default
      extends: defaultTheme(options),
    
      layouts: {
        // we override the default layout to provide comment service
        Layout: path.resolve(__dirname,"layout", "index.vue"),
      },
    });
    

    layout>index.vue

    <template>
      <ParentLayout>
        <template #page-bottom>
          <CommentService :darkmode="isDarkMode" />
        </template>
      </ParentLayout>
    </template>
    <script setup lang="ts">
    import { onBeforeUnmount, onMounted, ref } from "vue";
    import ParentLayout from "@vuepress/theme-default/lib/client/layouts/Layout.vue";
    const isDarkMode = ref(false);
    let observer;
    onMounted(() => {
      const html = document.querySelector("html") as HTMLElement;
      isDarkMode.value = html.classList.contains("dark");
      // watch theme change
      observer = new MutationObserver(() => {
        isDarkMode.value = html.classList.contains("dark");
      });
      observer.observe(html, {
        attributeFilter: ["class"],
        attributes: true,
      });
    });
    onBeforeUnmount(() => {
      observer.disconnect();
    });
    </script>
    

    然后应用主题
    my-book/docs/.vuepress/config.js修改主题属性如下

    const { commentPlugin } = require("vuepress-plugin-comment2");
    const { commentTheme } = require("./theme");
    
    module.exports = {
      ...
      theme: commentTheme({
        contributorsText: "作者",
        lastUpdatedText: "最后更新",
        sidebar,
        navbar: [
          {
            text: "博客",
            link: "https://www.cnblogs.com/dshvv",
          },
        ],
      }),
    
      plugins: [
        ...
        commentPlugin({
          provider: "Giscus",
          repo: "dshvv/red-treasure-book",
          repoId: "MDEwOlJlcG9zaXRvcnk0MDcxNDYxODA=",
          category: "Announcements",
          categoryId: "DIC_kwDOGESOxM4CPs5U",
        }),
      ],
    };
    
    
  • 相关阅读:
    Java——异步调用
    GTK3-demo 代码调用
    ef core code first 生成的数据库表去复数的方法
    nuxt全局挂载导航路由守卫
    vue导入,导出,列表展示excel数据
    JS之blob对象下载文件,解决word可能打开是乱码,xlsx文件打不开,图片显示格式不支持等问题
    程序猿的十一条浮躁表现
    RSA加密解密及加签验签
    冒泡排序
    Failed to parse source for import analysis because the content contains invalid JS syntax
  • 原文地址:https://www.cnblogs.com/dingshaohua/p/16382542.html
Copyright © 2020-2023  润新知