在 Hexo 博客上添加萌萌哒 Live 2D 模型

前言:

给你的博客添加萌萌哒 Live 2D 模型 ,让别人看到你的博客时感觉眼前一亮!


安装插件

1
npm install --save hexo-helper-live2d

配置文件

Hexo 的配置文件 _config.yml 中添加如下配置,详细配置可以参考文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
live2d:
enable: true
scriptFrom: local
pluginRootPath: live2dw/
pluginJsPath: lib/
pluginModelPath: assets/
tagMode: false
debug: false
model:
use: live2d-widget-model-hijiki
display:
position: right
width: 150
height: 300
mobile:
show: true
react:
opacity: 0.7

下载模型

下载模型,模型名称可以到这里参考,一些模型的预览可以在这里参考。

1
npm install live2d-widget-model-hijiki

配置文件

  1. Hexo 根目录中新建文件夹 live2d_models
  2. node_modules 文件夹中找到刚刚下载的 live2d 模型,将其复制到 live2d_models
    • live2d 模型是一个类似于这样的文件夹:live2d-widget-model-hijiki
  3. 编辑配置文件中的 model.use 项,将其修改为 live2d_models 文件夹中的模型文件夹的名称。

查看测试结果

在命令行(即 Git Bash)运行以下命令,在 http://127.0.0.1:4000/ 中查看效果

1
hexo clean && hexo g && hexo s

在最新版本的 Hexo-NexT 主题中,已经支持了 Live 2D 模型小部件,通过简单的配置,可以直接使用该小部件。

  1. 在站点根目录下创建并编辑 source/_data/head.njk ,向其中添加以下内容:
    1
    2
    // <script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script> 已被墙
    <script src="/static/js/autoload.js"></script>
  2. 然后取消 NexT 配置文件中 custom_file_path 部分下的 head 注释
    1
    2
    custom_file_path:
    head: source/_data/head.njk
  • 注意:jsdelivr 在中国已被墙,建议改为本地路径,需要手动在本地配置 autoload.js 路径,如:/static/js/autoload.js

参考链接

  1. live2d-widget
  2. live2dDemo
------------- 本文结束 感谢您的阅读 -------------
正在加载今日诗词....