Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.

Commit 2089561

Browse files
committed
feat: add custom path support for js on path
fix #95
1 parent 7e25de7 commit 2089561

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ An Example:
5959
live2d:
6060
enable: true
6161
scriptFrom: local
62+
onSiteRootPath: live2dw/
63+
pluginJsPath: lib/
64+
pluginModelPath: assets/
6265
model:
6366
use: live2d-widget-model-wanko
6467
display:
@@ -82,6 +85,9 @@ You can merge these two into your `_config.yml` file.
8285
live2d:
8386
enable: true
8487
# enable: false
88+
onSiteRootPath: live2dw/ # Root path of plugin to be on the site (Relative)
89+
pluginJsPath: lib/ # JavaScript path related to plugin's root (Relative)
90+
pluginModelPath: assets/ # Relative model path related to plugin's root (Relative)
8591
scriptFrom: local # Default
8692
# scriptFrom: jsdelivr # jsdelivr CDN
8793
# scriptFrom: unpkg # unpkg CDN

README.zh-CN.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ npm install --save hexo-helper-live2d
5858
live2d:
5959
enable: true
6060
scriptFrom: local
61+
onSiteRootPath: live2dw/
62+
pluginJsPath: lib/
63+
pluginModelPath: assets/
6164
model:
6265
use: live2d-widget-model-wanko
6366
display:
@@ -81,6 +84,9 @@ live2d:
8184
enable: true
8285
# enable: false
8386
scriptFrom: local # 默认
87+
onSiteRootPath: live2dw/ # 插件在站点上的根目录(相对路径)
88+
pluginJsPath: lib/ # 脚本文件相对与插件根目录路径
89+
pluginModelPath: assets/ # 模型文件相对与插件根目录路径
8490
# scriptFrom: jsdelivr # jsdelivr CDN
8591
# scriptFrom: unpkg # unpkg CDN
8692
# scriptFrom: https://cdn.jsdelivr.net/npm/live2d-widget@3.x/lib/L2Dwidget.min.js # 你的自定义 url

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ const thisPkgInfo = require('./package');
2525
const coreJsDepVer = thisPkgInfo.dependencies['live2d-widget'];
2626

2727
const blogRoot = hexo.config.root || '/';
28-
const onSiteRootPath = 'live2dw/';
29-
const onSiteJsPath = `${onSiteRootPath}lib/`;
30-
const onSiteModelPath = `${onSiteRootPath}assets/`;
3128

3229
const defaultConfig = {
3330
'enable': true,
31+
'pluginRootPath': 'live2dw/',
32+
'pluginJsPath': 'lib/',
33+
'pluginModelPath': 'assets/',
3434
'scriptFrom': 'local',
3535
};
3636

@@ -52,10 +52,10 @@ function getScriptURL (scriptFrom) {
5252
* Is local(1)
5353
* Use local
5454
*/
55-
const scriptGenerators = buildGeneratorsFromManifest(manifest, path.dirname(mainfestPath), onSiteJsPath);
55+
const scriptGenerators = buildGeneratorsFromManifest(manifest, path.dirname(mainfestPath), `${config.pluginRootPath}${config.pluginJsPath}`);
5656
const useHash = getFileMD5(path.resolve(path.dirname(mainfestPath), coreScriptName));
5757
generators.push(...scriptGenerators);
58-
return `${blogRoot}${url.resolve(onSiteJsPath, coreScriptName)}?${useHash}`;
58+
return `${blogRoot}${url.resolve(`${config.pluginRootPath}${config.pluginJsPath}`, coreScriptName)}?${useHash}`;
5959

6060
}
6161
case 'jsdelivr':
@@ -100,7 +100,7 @@ if (config.enable) {
100100
const {
101101
modelGenerators,
102102
'modelJsonUrl': pkgModelJsonUrl,
103-
} = loadModelFrom(tryPath, onSiteModelPath);
103+
} = loadModelFrom(tryPath, `${config.pluginRootPath}${config.pluginModelPath}`);
104104
modelJsonUrl = `${blogRoot}${pkgModelJsonUrl}`;
105105
generators.push(...modelGenerators);
106106
print.log(`Loaded model from live2d_models folder(2), '${url.parse(modelJsonUrl).pathname}' from '${tryPath}'`);
@@ -117,7 +117,7 @@ if (config.enable) {
117117
const {
118118
modelGenerators,
119119
'modelJsonUrl': pkgModelJsonUrl,
120-
} = loadModelFrom(tryPath, onSiteModelPath);
120+
} = loadModelFrom(tryPath, `${config.pluginRootPath}${config.pluginModelPath}`);
121121
modelJsonUrl = `${blogRoot}${pkgModelJsonUrl}`;
122122
generators.push(...modelGenerators);
123123
print.log(`Loaded model from hexo base releated path(3), '${url.parse(modelJsonUrl).pathname}' from '${tryPath}'`);
@@ -144,7 +144,7 @@ if (config.enable) {
144144
const {
145145
modelGenerators,
146146
'modelJsonUrl': pkgModelJsonUrl,
147-
} = loadModelFrom(assetsDir, onSiteModelPath);
147+
} = loadModelFrom(assetsDir, `${config.pluginRootPath}${config.pluginModelPath}`);
148148
modelJsonUrl = `${blogRoot}${pkgModelJsonUrl}`;
149149
generators.push(...modelGenerators);
150150
print.log(`Loaded model from npm-module(1), ${packageJsonObj.name}@${packageJsonObj.version} from '${assetsDir}'`);

0 commit comments

Comments
 (0)