搭建 VuePress 博客,你可能会用到的一些插件

简介: 「这是我参与2022首次更文挑战的第8天,活动详情查看:2022首次更文挑战」。

0.png


「这是我参与2022首次更文挑战的第8天,活动详情查看:2022首次更文挑战」。


前言


《一篇带你用 VuePress + Github Pages 搭建博客》中,我们使用 VuePress 搭建了一个博客,最终的效果查看:TypeScript 中文文档


为了丰富站点的功能,我们可以直接使用一些现有的插件,本篇我们讲讲一些常用的插件。


1. 公告栏弹窗


插件地址:vuepress-theme-reco.recoluan.com/views/plugi…


安装:


yarn add @vuepress-reco/vuepress-plugin-bulletin-popover -D
复制代码


使用:


plugins: [
  ['@vuepress-reco/vuepress-plugin-bulletin-popover', {
    width: '300px', // 默认 260px
    title: '消息提示',
    body: [
      {
        type: 'title',
        content: '添加冴羽好友入前端交流群',
        style: 'text-aligin: center;'
      },
      {
        type: 'image',
        src: 'https://cdn.jsdelivr.net/gh/mqyqingfeng/picture/IMG_3516.JPG'
      }
    ],
    footer: [
      {
        type: 'button',
        text: '打赏',
        link: '/donate'
      } 
    ]
  }]
]
复制代码


效果截图:


7.png


注意事项:


查看插件源码可以得知,公告栏弹窗是使用 sessionStorage 控制的展示频次,在本地测试时,如果关闭了,可以通过清除 sessionStorage 再次展示出来。


// 所在目录:node_modules/@vuepress-reco/vuepress-plugin-bulletin-popover/bin/Bulletin.vue
mounted () {
    const closeNote = sessionStorage.getItem('closeNote')
    this.visible = closeNote !== 'true'
}
复制代码


2. 代码复制


插件地址:www.npmjs.com/package/vue…


安装:


yarn add vuepress-plugin-nuggets-style-copy -D
复制代码


使用:


plugins: [
  ["vuepress-plugin-nuggets-style-copy", {
      copyText: "复制代码",
      tip: {
          content: "复制成功"
      }
   }]
]
复制代码


效果类似于掘金的代码复制:


8.png


其他样式的代码复制插件还有:


  1. github.com/znicholasbr…
  2. snippetors.github.io/plugins/vue…


3. 添加著作权信息


使用 vuepress-plugin-copyright可以禁用文字复制或者在复制时添加著作权信息。


插件地址:vuepress-community.netlify.app/zh/plugins/…


安装:


yarn add vuepress-plugin-copyright -D
复制代码


使用:


plugins: [
  [
    'copyright',
    {
      authorName: '冴羽', // 选中的文字将无法被复制
      minLength: 30, // 如果长度超过  30 个字符
    },
  ]
]
复制代码


当你复制超过 30 个字符的时候,就会出现:


著作权归冴羽所有。
链接:http://localhost:8080/learn-typescript/handbook/Basic.html
JavaScript 的每个值执行不同的操作时会有不同的行为。这听起来有点抽象,所以让我们举个例子,假设我们有一个名为 message 的变量,试想我们可以做哪些操作: 
复制代码


4. 背景音乐


插件地址:vuepress-theme-reco.recoluan.com/views/plugi…


安装:


yarn add @vuepress-reco/vuepress-plugin-bgm-player -D
复制代码


使用:


plugins: [
  [
    '@vuepress-reco/vuepress-plugin-bgm-player',
    {
      audios: [
        {
          name: 'LOSER',
          artist: '米津玄師',
          url: 'https://www.ytmp3.cn/down/73654.mp3',
          cover: 'https://p1.music.126.net/qTSIZ27qiFvRoKj-P30BiA==/109951165895951287.jpg?param=200y200'
        }
      ] ,
      // 是否默认缩小
      autoShrink: true ,
      // 缩小时缩为哪种模式
      shrinkMode: 'float',
      // 悬浮窗样式
      floatStyle:{ bottom: '10px', 'z-index': '999999' }
    }
  ]
]
复制代码


其他音乐插件:


  1. github.com/moefyit/vue…
  2. juejin.cn/post/704594…


5. 看板娘


插件地址:vuepress-theme-reco.recoluan.com/views/plugi…


安装:


yarn add @vuepress-reco/vuepress-plugin-kan-ban-niang -D
复制代码


使用:


plugins: [
  [
    '@vuepress-reco/vuepress-plugin-kan-ban-niang',
    {
      theme: ['blackCat', 'whiteCat', 'haru1', 'haru2', 'haruto', 'koharu', 'izumi', 'shizuku', 'wanko', 'miku', 'z16']
    }
  ]
]
复制代码


其他看板娘插件:


  1. github.com/yanjun0501/…


6. 修改光标效果


插件地址:github.com/moefyit/vue…


安装:


yarn add vuepress-plugin-cursor-effects -D
复制代码


使用:


plugins: [
  ['cursor-effects', {
    size: 2, // size of the particle, default: 2
    shape: 'star', // ['star' | 'circle'], // shape of the particle, default: 'star'
    zIndex: 999999999, // z-index property of the canvas, default: 999999999
  }]
]
复制代码


7. 动态标题展示


插件地址:github.com/moefyit/vue…


安装:


yarn add vuepress-plugin-dynamic-title -D
复制代码


使用:


plugins: [
  ['dynamic-title', {
     showIcon: 'https://www.typescriptlang.org/favicon-32x32.png?v=8944a05a8b601855de116c8a56d3b3ae',
     showText: '客官欢迎回来~',
     hideIcon: 'https://www.typescriptlang.org/favicon-32x32.png?v=8944a05a8b601855de116c8a56d3b3ae',
     hideText: '客官不要走嘛~',
     recoverTime: 2000,
  }]
]  
复制代码


8. 优化代码展示


插件地址:vuepress-theme-reco.recoluan.com/views/plugi…


安装:


yarn add @vuepress-reco/vuepress-plugin-extract-code -D
复制代码


使用:


plugins: [
    '@vuepress-reco/extract-code'
  ]
复制代码


当你需要使用这种方式展示代码的时候,你需要在 md 文件中添加:


<RecoDemo :collapse="true">
  <template slot="code-bash">
    <<< @/docs/handbook/demo/index.sh
  </template>
  <template slot="code-js">
    <<< @/docs/handbook/demo/index.js
  </template>
  <img src="./demo/index.gif" slot="demo" />
</RecoDemo>
复制代码


其中的@表示当前项目目录的别名,即源码的根目录,而非docs或者 .vuepress


更多插件寻找


  1. github.com/vuepress/aw…


  1. vuepress-community.netlify.app/zh/


  1. vuepress-theme-reco.recoluan.com/views/plugi…


  1. v1.vuepress.vuejs.org/zh/plugin/o…


  1. npm 搜 vuepress-plugin 关键字


  1. github 搜 vuepress-plugin 关键字


系列文章


博客搭建系列是我至今写的唯一一个偏实战的系列教程,预计 20 篇左右,讲解如何使用 VuePress 搭建、优化博客,并部署到 GitHub、Gitee、私有服务器等平台。本篇为第 21 篇,全系列文章地址:github.com/mqyqingfeng…


微信:「mqyqingfeng」,加我进冴羽唯一的读者群。


如果有错误或者不严谨的地方,请务必给予指正,十分感谢。如果喜欢或者有所启发,欢迎 star,对作者也是一种鼓励。



目录
相关文章
|
7月前
|
JavaScript Shell 网络安全
hexo博客1:环境配置
hexo博客1:环境配置
74 0
|
9月前
|
Web App开发 域名解析 JavaScript
3分钟搭建个人Hexo博客
从账号的创建到一键部署,手把手教你零基础创建个人博客,后续可以继续根据网上的教程来修改代码对博客进行定制化的美化。
73 1
YI
|
11月前
|
JavaScript Shell Linux
Hexo博客搭建1
暑假在家学习时,突然感觉学过的知识忘记的很快,所以决定搭建个人博客来记录学习过程。经过前期了解后,决定采用Hexo框架来搭建个人博客。本文将记录博客搭建过程。
YI
79 0
YI
|
11月前
|
Shell
Hexo博客搭建3
之前的文章介绍了博客的本地搭建和线上部署。因为hexo的内置主题不够好看,所以我们可以选择加载其他主题来美化我们的博客页面。本文我将介绍基于hexo框架搭建的博客如何修改主题。
YI
54 0
YI
|
11月前
|
Shell 开发工具 数据安全/隐私保护
Hexo博客搭建2
上一篇介绍了博客的本地环境搭建,但这只能本地访问自己的博客。如果想让自己的博客被互联网上的其他人访问,我们还需要将博客项目进行线上部署。本文我将介绍将博客部署到github上的方法。
YI
52 0
|
JavaScript
使用 hexo 框架 快速搭建个人博客(一)
使用 hexo 框架 快速搭建个人博客(一)
132 0
使用 hexo 框架 快速搭建个人博客(一)
|
开发工具 数据安全/隐私保护 git
使用 hexo 框架 快速搭建个人博客(二)
使用 hexo 框架 快速搭建个人博客(二)
106 0
使用 hexo 框架 快速搭建个人博客(二)
|
自然语言处理 数据可视化
使用vuepress-theme-reco搭建自己的博客
你想搭建属于你自己的博客吗?你想将你的笔记可视化吗?快来学些Markdown笔记一键生成网页的方法吧!
364 1
使用vuepress-theme-reco搭建自己的博客
|
JavaScript Shell Linux
使用Hexo搭建自己的博客
之前一直在用typecho来做自己的博客,因为他操作比较简单,但是前几日修改一些配置的时候,看着满屏的php代码实在有些头疼,在朋友的推荐下,我成功的入坑了hexo,下面分享一些自己搭建博客的过程,尽量让读者避开一些坑。
|
JavaScript 前端开发
VuePress 博客搭建系列 33 篇正式完结
本篇聊一聊我为什么会写这个系列,以及写作这个系列中的一些感悟。
333 0
VuePress 博客搭建系列 33 篇正式完结