hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.62k stars 4.87k forks source link

Injector doesn't seem to work. #4451

Closed KumaNNN closed 4 years ago

KumaNNN commented 4 years ago

Check List

Please check followings before submitting a new issue.

Question

Environment & Settings

Node.js & npm version

node --version
v12.18.1

 npm --version
6.14.5

Your site _config.yml (Optional)

Your theme _config.yml (Optional)

Hexo and Plugin version(npm ls --depth 0)

+-- @hapi/hawk@8.0.0
+-- @hapi/sntp@4.0.0
+-- bcryptjs@2.4.3
+-- boom@7.3.0
+-- chokidar@3.4.1
+-- connect@3.7.0
+-- core-js@3.6.5
+-- cryptiles@4.1.3
+-- ejs@3.1.3
+-- gifsicle@5.1.0
+-- hexo@4.2.1
+-- hexo-abbrlink@2.2.1
+-- hexo-admin@2.3.0
+-- hexo-admonition@1.1.2
+-- hexo-all-minifier@0.5.3
+-- hexo-auto-category@0.2.0
+-- hexo-autolinker@1.0.1
+-- hexo-bilibili-bangumi@1.3.5
+-- hexo-deployer-git@2.1.0
+-- hexo-excerpt@1.1.6
+-- hexo-filter-flowchart@1.0.4
+-- hexo-filter-nofollow@2.0.2
+-- hexo-filter-sequence@1.0.3
+-- hexo-generator-archive@1.0.0
+-- hexo-generator-category@1.0.0
+-- hexo-generator-feed@2.2.0
+-- hexo-generator-index@1.0.0
+-- hexo-generator-json-content@4.2.3
+-- hexo-generator-restful@0.2.3
+-- hexo-generator-search@2.4.0
+-- hexo-generator-searchdb@1.3.2
+-- hexo-generator-sitemap@2.0.0
+-- hexo-generator-tag@1.0.0
+-- hexo-generator-topindex@0.3.0
+-- hexo-github-card@1.0.5
+-- hexo-include@1.1.0
+-- hexo-lazyload-image@1.0.9
+-- hexo-reference@1.0.4
+-- hexo-related-popular-posts@4.0.0
+-- hexo-renderer-ejs@1.0.0
+-- hexo-renderer-markdown-it@4.1.0
+-- hexo-renderer-stylus@1.1.0
+-- hexo-server@1.0.0
+-- hexo-symbols-count-time@0.7.1
+-- hexo-tag-demo@0.2.10
+-- hexo-tag-mmedia@0.1.6
+-- hexo-valkyr-url@1.1.0
+-- hoek@6.1.3
+-- imagemin-gifsicle@7.0.0
+-- minimatch@3.0.4
`-- object-assign@4.1.1

Your package.json package.json

Others

注入器(https://hexo.io/zh-cn/api/injector) 好像不工作,不存在hexo.extend.injector,我在插件或Script目录下使用如下代码 The injector doesn't seem to work. hexo.extend.injector doesn't exist. I use the following code in the plug-in or script directory

const css = hexo.extend.helper.get('css');
hexo.extend.injector.register('head_end', () => {
  return css('/css/hexo-admonition.css');
}, 'default'); 

返回错误 Retrun Error

...
TypeError: Cannot read property 'register' of undefined
...

在代码中dump,未发现有injector对象 Debugging in code, no injector objects found.

console.log(hexo.extend); 
SukkaW commented 4 years ago

Upgrade hexo to 5.0.0 first. Injector API is firstly introduced in Hexo 5.0.0.