Hexo添加Live2d模型

Hexo添加Live2d模型

方法一:使用 hexo-helper-live2d

Installations

  1. 首先在网站根目录下执行npm install --save hexo-helper-live2d,下载 Live2d 插件

  2. 下载模型,在网站根目录下新建live2d_models文件夹,将模型文件放入其中,模型文件可在以下链接下载
    https://github.com/xiazeyu/live2d-widget-models

  3. 修改_config.yml文件,添加如下配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    live2d:
    enable: true
    model:
    use: nipsilon # 相对于/live2d_models/的路径
    display:
    position: left
    width: 175
    height: 350
    log: true
    mobile:
    show: false

    文件的存放位置参考下图

  4. 效果图

Configurations

helper 特有

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Live2D
## https://github.com/EYHN/hexo-helper-live2d
live2d:
enable: true
# enable: false
scriptFrom: local # 默认
pluginRootPath: live2dw/ # 插件在站点上的根目录(相对路径)
pluginJsPath: lib/ # 脚本文件相对与插件根目录路径
pluginModelPath: assets/ # 模型文件相对与插件根目录路径
# scriptFrom: jsdelivr # jsdelivr CDN
# scriptFrom: unpkg # unpkg CDN
# scriptFrom: https://cdn.jsdelivr.net/npm/live2d-widget@3.x/lib/L2Dwidget.min.js # 你的自定义 url
tagMode: false # 标签模式, 是否仅替换 live2d tag标签而非插入到所有页面中
debug: false # 调试, 是否在控制台输出日志
model:
use: live2d-widget-model-wanko # npm-module package name
# use: wanko # 博客根目录/live2d_models/ 下的目录名
# use: ./wives/wanko # 相对于博客根目录的路径
# use: https://cdn.jsdelivr.net/npm/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json # 你的自定义 url

General Settings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Live2D
## https://github.com/xiazeyu/live2d-widget.js
## https://l2dwidget.js.org/docs/class/src/index.js~L2Dwidget.html#instance-method-init
live2d:
model:
scale: 1
hHeadPos: 0.5
vHeadPos: 0.618
display:
superSample: 2
width: 150
height: 300
position: right
hOffset: 0
vOffset: -20
mobile:
show: true
scale: 0.5
react:
opacityDefault: 0.7
opacityOnHover: 0.2

方法二:使用 live2d-widget

相比方法一,方法二支持更丰富的特性,见Live2D Widget

对于 Icarus,在<blog_root_folder>\themes\icarus\layout\layout.jsx末尾添加<script src="https://fastly.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>然后运行hexo s即可看到 live2d-model

或者,你也可以克隆项目到本地,例如在/theme/icarus/source/js/live2d/中克隆项目,并修改``layout.jsvautoload.js`;

如果需要修改样式,可自行更改waifu.css live2d.min.js waifu-tips.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
File: themes\icarus\layout\layout.jsx
module.exports = class extends Component {
render() {
const { site, config, page, helper, body } = this.props;

const language = page.lang || page.language || config.language;
const columnCount = Widgets.getColumnCount(config.widgets, config, page);

return <html lang={language ? language.substr(0, 2) : ''}>
<Head site={site} config={config} helper={helper} page={page} />
<body class={`is-${columnCount}-column`}>

<Footer config={config} helper={helper} />
<Scripts site={site} config={config} helper={helper} page={page} />
<Search config={config} helper={helper} />
......
// Note Here you can inject custom scripts
+ <script type="text/javascript" src="/js/live2d/autoload.js"></script>
</body>
</html>;
}
};

File: public\js\live2d\autoload.js
// live2d_path 参数建议使用绝对路径
- const live2d_path = "https://fastly.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/";
+ const live2d_path = "/js/live2d/";

// 封装异步加载资源的方法
function loadExternalResource(url, type) {
}

// 加载 waifu.css live2d.min.js waifu-tips.js
if (screen.width >= 768) {
}

如果模型显示过程中被覆盖,可适当调大z-index,使其置于网页上层

Ref

hexo-helper-live2d
Hexo 添加 Live2D 看板娘+模型预览

Author

Efterklang

Posted on

2024-04-26

Updated on

2024-09-18

Licensed under

Comments