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

Commit

Permalink
feat: add log
Browse files Browse the repository at this point in the history
fix #118
  • Loading branch information
xiazeyu committed Jul 14, 2018
1 parent bc1b905 commit 3ce80f0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug-report-----.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ about: 创造一个报告以便更好地迭代
复现此问题的步骤

出现问题的网站地址:
**`log` 选项设置为 `true`**
`_config.yml` 中的配置:

```yaml
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ live2d:
```
URL:
**Turn `log` config to `true`**
Console output:

1. Go to '...'
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ live2d:
pluginJsPath: lib/
pluginModelPath: assets/
tagMode: false
debug: false
model:
use: live2d-widget-model-wanko
display:
Expand Down Expand Up @@ -110,7 +111,8 @@ live2d:
# scriptFrom: jsdelivr # jsdelivr CDN
# scriptFrom: unpkg # unpkg CDN
# scriptFrom: https://cdn.jsdelivr.net/npm/[email protected]/lib/L2Dwidget.min.js # Your custom url
tagMode: false # Specifies whether only to replace live2d tag instead of inject to all pages
tagMode: false # Whether only to replace live2d tag instead of inject to all pages
debug: false # Whether to show logs in console
model:
use: live2d-widget-model-wanko # npm-module package name
# use: wanko # folder name in (hexo base dir)/live2d_models/
Expand Down
2 changes: 2 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ live2d:
pluginJsPath: lib/
pluginModelPath: assets/
tagMode: false
debug: false
model:
use: live2d-widget-model-wanko
display:
Expand Down Expand Up @@ -109,6 +110,7 @@ live2d:
# scriptFrom: unpkg # unpkg CDN
# scriptFrom: https://cdn.jsdelivr.net/npm/[email protected]/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/ 下的目录名
Expand Down
46 changes: 38 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const blogRoot = hexo.config.root || '/';

const defaultConfig = {
'enable': true,
'log': false,
'pluginJsPath': 'lib/',
'pluginModelPath': 'assets/',
'pluginRootPath': 'live2dw/',
Expand All @@ -44,9 +45,13 @@ let config = _.defaultsDeep({
* @param {String} scriptFrom The type of source
* @return {String} URL of entry point
*/
function getScriptURL (scriptFrom) {
function getScriptURL (scriptFrom) { // eslint-disable-line max-lines-per-function

print.log(`hexo-helper-live2d@${thisPkgInfo.version}, using live2d-widget@${widgetVer}.`);
if (config.log) {

print.log(`hexo-helper-live2d@${thisPkgInfo.version}, using live2d-widget@${widgetVer}.`);

}

switch (scriptFrom) {

Expand All @@ -56,7 +61,11 @@ function getScriptURL (scriptFrom) {
* Is local(1)
* Use local
*/
print.log(`use local live2d-widget@${localWidgetVer}`);
if (config.log) {

print.log(`use local live2d-widget@${localWidgetVer}`);

}
const scriptGenerators = buildGeneratorsFromManifest(manifest, path.dirname(mainfestPath), `${config.pluginRootPath}${config.pluginJsPath}`);
const useHash = getFileMD5(path.resolve(path.dirname(mainfestPath), coreScriptName));
generators.push(...scriptGenerators);
Expand Down Expand Up @@ -108,7 +117,11 @@ if (config.enable) {
} = loadModelFrom(tryPath, `${config.pluginRootPath}${config.pluginModelPath}`);
modelJsonUrl = `${blogRoot}${pkgModelJsonUrl}`;
generators.push(...modelGenerators);
print.log(`Loaded model from live2d_models folder(2), '${url.parse(modelJsonUrl).pathname}' from '${tryPath}'`);
if (config.log) {

print.log(`Loaded model from live2d_models folder(2), '${url.parse(modelJsonUrl).pathname}' from '${tryPath}'`);

}

} else {

Expand All @@ -125,7 +138,11 @@ if (config.enable) {
} = loadModelFrom(tryPath, `${config.pluginRootPath}${config.pluginModelPath}`);
modelJsonUrl = `${blogRoot}${pkgModelJsonUrl}`;
generators.push(...modelGenerators);
print.log(`Loaded model from hexo base releated path(3), '${url.parse(modelJsonUrl).pathname}' from '${tryPath}'`);
if (config.log) { // eslint-disable-line max-depth

print.log(`Loaded model from hexo base releated path(3), '${url.parse(modelJsonUrl).pathname}' from '${tryPath}'`);

}

} else if (getNodeModulePath(config.model.use) === null) {

Expand All @@ -134,7 +151,11 @@ if (config.enable) {
* Use custom
*/
modelJsonUrl = config.model.use;
print.log(`Loaded Model from custom(4), at '${modelJsonUrl}'`);
if (config.log) { // eslint-disable-line max-depth

print.log(`Loaded Model from custom(4), at '${modelJsonUrl}'`);

}

} else {

Expand All @@ -152,7 +173,11 @@ if (config.enable) {
} = loadModelFrom(assetsDir, `${config.pluginRootPath}${config.pluginModelPath}`);
modelJsonUrl = `${blogRoot}${pkgModelJsonUrl}`;
generators.push(...modelGenerators);
print.log(`Loaded model from npm-module(1), ${packageJsonObj.name}@${packageJsonObj.version} from '${assetsDir}'`);
if (config.log) { // eslint-disable-line max-depth

print.log(`Loaded model from npm-module(1), ${packageJsonObj.name}@${packageJsonObj.version} from '${assetsDir}'`);

}

}

Expand All @@ -174,6 +199,11 @@ if (config.enable) {

hexo.extend.helper.register('live2d', () => {

if (config.log) {

print.log('live2d tag detected, use tagMode.');

}
const scriptToInject = `L2Dwidget.init(${JSON.stringify(config)});`;
const contentToInject = `<script src="${scriptUrlToInject}"></script><script>${scriptToInject}</script>`;
return contentToInject;
Expand All @@ -184,7 +214,7 @@ if (config.enable) {

hexo.extend.helper.register('live2d', () => {

print.warn('live2d tag was detected, but won\'t be use. Make sure \'tagMode\' config is expected. See #36, #122.');
print.warn('live2d tag detected, but won\'t be use. Make sure \'tagMode\' config is expected. See #36, #122.');

});

Expand Down

0 comments on commit 3ce80f0

Please sign in to comment.