Skip to content

Commit

Permalink
Merge pull request hexojs#1485 from curbengh/injector-bind-2
Browse files Browse the repository at this point in the history
docs(injector): helper must bind to hexo context
  • Loading branch information
curbengh authored Aug 10, 2020
2 parents 7479e6b + 057b887 commit b49b861
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 29 deletions.
10 changes: 5 additions & 5 deletions source/api/injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ There are other internal functions, see [hexojs/hexo#4049](https://github.com/he
## Example

```js
const css = hexo.extend.helper.get('css');
const js = hexo.extend.helper.get('js');
const css = hexo.extend.helper.get('css').bind(hexo);
const js = hexo.extend.helper.get('js').bind(hexo);

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
Expand All @@ -62,15 +62,14 @@ hexo.extend.injector.register('body_end', () => {

Above setup will inject `APlayer.min.css` (`<link>` tag) to the `</head>` of any page which layout is `music`, and `APlayer.min.js` (`<script>` tag) to the `</body>` of those pages. Also, `jquery.js` (`<script>` tag) will be injected to `</body>` of every page generated.


## Accessing user configuration

Use any of the following options:

1.

``` js
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);

hexo.extend.injector.register('head_end', () => {
const { cssPath } = hexo.config.fooPlugin;
Expand Down Expand Up @@ -115,14 +114,15 @@ hexo.extend.injector.register('head_end', require('./lib/inject')(hexo))

``` js lib/inject.js
module.exports = (hexo) => () => {
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
```

``` js lib/inject.js
const injectFn = (hexo) => {
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
Expand Down
9 changes: 5 additions & 4 deletions source/ko/api/injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ There are other internal functions, see [hexojs/hexo#4049](https://github.com/he
## Example

```js
const css = hexo.extend.helper.get('css');
const js = hexo.extend.helper.get('js');
const css = hexo.extend.helper.get('css').bind(hexo);
const js = hexo.extend.helper.get('js').bind(hexo);

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
Expand All @@ -69,7 +69,7 @@ Use any of the following options:
1.

``` js
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);

hexo.extend.injector.register('head_end', () => {
const { cssPath } = hexo.config.fooPlugin;
Expand Down Expand Up @@ -114,14 +114,15 @@ hexo.extend.injector.register('head_end', require('./lib/inject')(hexo))

``` js lib/inject.js
module.exports = (hexo) => () => {
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
```

``` js lib/inject.js
const injectFn = (hexo) => {
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
Expand Down
9 changes: 5 additions & 4 deletions source/pt-br/api/injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ There are other internal functions, see [hexojs/hexo#4049](https://github.com/he
## Example

```js
const css = hexo.extend.helper.get('css');
const js = hexo.extend.helper.get('js');
const css = hexo.extend.helper.get('css').bind(hexo);
const js = hexo.extend.helper.get('js').bind(hexo);

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
Expand All @@ -69,7 +69,7 @@ Use any of the following options:
1.

``` js
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);

hexo.extend.injector.register('head_end', () => {
const { cssPath } = hexo.config.fooPlugin;
Expand Down Expand Up @@ -114,14 +114,15 @@ hexo.extend.injector.register('head_end', require('./lib/inject')(hexo))

``` js lib/inject.js
module.exports = (hexo) => () => {
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
```

``` js lib/inject.js
const injectFn = (hexo) => {
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
Expand Down
9 changes: 5 additions & 4 deletions source/ru/api/injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ There are other internal functions, see [hexojs/hexo#4049](https://github.com/he
## Example

```js
const css = hexo.extend.helper.get('css');
const js = hexo.extend.helper.get('js');
const css = hexo.extend.helper.get('css').bind(hexo);
const js = hexo.extend.helper.get('js').bind(hexo);

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
Expand All @@ -69,7 +69,7 @@ Use any of the following options:
1.

``` js
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);

hexo.extend.injector.register('head_end', () => {
const { cssPath } = hexo.config.fooPlugin;
Expand Down Expand Up @@ -114,14 +114,15 @@ hexo.extend.injector.register('head_end', require('./lib/inject')(hexo))

``` js lib/inject.js
module.exports = (hexo) => () => {
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
```

``` js lib/inject.js
const injectFn = (hexo) => {
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
Expand Down
9 changes: 5 additions & 4 deletions source/th/api/injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ There are other internal functions, see [hexojs/hexo#4049](https://github.com/he
## Example

```js
const css = hexo.extend.helper.get('css');
const js = hexo.extend.helper.get('js');
const css = hexo.extend.helper.get('css').bind(hexo);
const js = hexo.extend.helper.get('js').bind(hexo);

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
Expand All @@ -69,7 +69,7 @@ Use any of the following options:
1.

``` js
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);

hexo.extend.injector.register('head_end', () => {
const { cssPath } = hexo.config.fooPlugin;
Expand Down Expand Up @@ -114,14 +114,15 @@ hexo.extend.injector.register('head_end', require('./lib/inject')(hexo))

``` js lib/inject.js
module.exports = (hexo) => () => {
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
```

``` js lib/inject.js
const injectFn = (hexo) => {
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
Expand Down
9 changes: 5 additions & 4 deletions source/zh-cn/api/injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ hexo.extend.injector.register(entry, value, to)
## 样例

```js
const css = hexo.extend.helper.get('css');
const js = hexo.extend.helper.get('js');
const css = hexo.extend.helper.get('css').bind(hexo);
const js = hexo.extend.helper.get('js').bind(hexo);

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
Expand All @@ -67,7 +67,7 @@ Use any of the following options:
1.

``` js
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);

hexo.extend.injector.register('head_end', () => {
const { cssPath } = hexo.config.fooPlugin;
Expand Down Expand Up @@ -112,14 +112,15 @@ hexo.extend.injector.register('head_end', require('./lib/inject')(hexo))

``` js lib/inject.js
module.exports = (hexo) => () => {
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
```

``` js lib/inject.js
const injectFn = (hexo) => {
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
Expand Down
9 changes: 5 additions & 4 deletions source/zh-tw/api/injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ There are other internal functions, see [hexojs/hexo#4049](https://github.com/he
## Example

```js
const css = hexo.extend.helper.get('css');
const js = hexo.extend.helper.get('js');
const css = hexo.extend.helper.get('css').bind(hexo);
const js = hexo.extend.helper.get('js').bind(hexo);

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
Expand All @@ -69,7 +69,7 @@ Use any of the following options:
1.

``` js
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);

hexo.extend.injector.register('head_end', () => {
const { cssPath } = hexo.config.fooPlugin;
Expand Down Expand Up @@ -114,14 +114,15 @@ hexo.extend.injector.register('head_end', require('./lib/inject')(hexo))

``` js lib/inject.js
module.exports = (hexo) => () => {
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
```

``` js lib/inject.js
const injectFn = (hexo) => {
const css = hexo.extend.helper.get('css');
const css = hexo.extend.helper.get('css').bind(hexo);
const { cssPath } = hexo.config.fooPlugin;
return css(cssPath);
};
Expand Down

0 comments on commit b49b861

Please sign in to comment.