Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(injector): bring up #1451

Merged
merged 2 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/_data/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ api:
filter: filter.html
generator: generator.html
helper: helper.html
injector: injector.html
migrator: migrator.html
processor: processor.html
renderer: renderer.html
Expand Down
63 changes: 63 additions & 0 deletions source/api/injector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
title: Injector
---

An injector is used to add static code snippet to the `<head>` or/and `<body>` of generated HTML files. Hexo run injector **before** `after_render:html` filter is executed.

## Synopsis

```js
hexo.extend.injector.register(entry, value, to)
```

### entry `<string>`

Where the code will be injected inside the HTML.

Support those values:

- `head_begin`: Inject code snippet right after `<head>` (Default).
- `head_end`: Inject code snippet right before `</head>`.
- `body_begin`: Inject code snippet right after `<body>`.
- `body_end`: Inject code snippet right before `</body>`.

### value `<string> | <Function>`

> A function that returns string is supported.

The code snippet to be injected.

### to `<string>`

Which page will code snippets being injected.

- `default`: Inject to every page (Default).
- `home`: Only inject to home page (which has `is_home()` helper being `true`)
- `post`: Only inject to post pages (which has `is_post()` helper being `true`)
- `page`: Only inject to pages (which has `is_page()` helper being `true`)
- `archive`: Only inject to archive pages (which has `is_archive()` helper being `true`)
- `category`: Only inject to category pages (which has `is_category()` helper being `true`)
- `tag`: Only inject to tag pages (which has `is_tag()` helper being `true`)
- Custom layout name could be used as well, see [Writing - Layout](writing#Layout).

----

There are other internal functions, see [hexojs/hexo#4049](https://github.com/hexojs/hexo/pull/4049) for more details.

## Example

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

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
}, 'music');

hexo.extend.injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.js">', 'music');

hexo.extend.injector.register('body_end', () => {
return js('/js/jquery.js');
});
```

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.
63 changes: 63 additions & 0 deletions source/ko/api/injector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
title: Injector
---

An injector is used to add static code snippet to the `<head>` or/and `<body>` of generated HTML files. Hexo run injector **before** `after_render:html` filter is executed.

## Synopsis

```js
hexo.extend.injector.register(entry, value, to)
```

### entry `<string>`

Where the code will be injected inside the HTML.

Support those values:

- `head_begin`: Inject code snippet right after `<head>` (Default).
- `head_end`: Inject code snippet right before `</head>`.
- `body_begin`: Inject code snippet right after `<body>`.
- `body_end`: Inject code snippet right before `</body>`.

### value `<string> | <Function>`

> A function that returns string is supported.

The code snippet to be injected.

### to `<string>`

Which page will code snippets being injected.

- `default`: Inject to every page (Default).
- `home`: Only inject to home page (which has `is_home()` helper being `true`)
- `post`: Only inject to post pages (which has `is_post()` helper being `true`)
- `page`: Only inject to pages (which has `is_page()` helper being `true`)
- `archive`: Only inject to archive pages (which has `is_archive()` helper being `true`)
- `category`: Only inject to category pages (which has `is_category()` helper being `true`)
- `tag`: Only inject to tag pages (which has `is_tag()` helper being `true`)
- Custom layout name could be used as well, see [Writing - Layout](writing#Layout).

----

There are other internal functions, see [hexojs/hexo#4049](https://github.com/hexojs/hexo/pull/4049) for more details.

## Example

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

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
}, 'music');

hexo.extend.injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.js">', 'music');

hexo.extend.injector.register('body_end', () => {
return js('/js/jquery.js');
});
```

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.
63 changes: 63 additions & 0 deletions source/pt-br/api/injector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
title: Injector
---

An injector is used to add static code snippet to the `<head>` or/and `<body>` of generated HTML files. Hexo run injector **before** `after_render:html` filter is executed.

## Synopsis

```js
hexo.extend.injector.register(entry, value, to)
```

### entry `<string>`

Where the code will be injected inside the HTML.

Support those values:

- `head_begin`: Inject code snippet right after `<head>` (Default).
- `head_end`: Inject code snippet right before `</head>`.
- `body_begin`: Inject code snippet right after `<body>`.
- `body_end`: Inject code snippet right before `</body>`.

### value `<string> | <Function>`

> A function that returns string is supported.

The code snippet to be injected.

### to `<string>`

Which page will code snippets being injected.

- `default`: Inject to every page (Default).
- `home`: Only inject to home page (which has `is_home()` helper being `true`)
- `post`: Only inject to post pages (which has `is_post()` helper being `true`)
- `page`: Only inject to pages (which has `is_page()` helper being `true`)
- `archive`: Only inject to archive pages (which has `is_archive()` helper being `true`)
- `category`: Only inject to category pages (which has `is_category()` helper being `true`)
- `tag`: Only inject to tag pages (which has `is_tag()` helper being `true`)
- Custom layout name could be used as well, see [Writing - Layout](writing#Layout).

----

There are other internal functions, see [hexojs/hexo#4049](https://github.com/hexojs/hexo/pull/4049) for more details.

## Example

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

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
}, 'music');

hexo.extend.injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.js">', 'music');

hexo.extend.injector.register('body_end', () => {
return js('/js/jquery.js');
});
```

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.
63 changes: 63 additions & 0 deletions source/ru/api/injector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
title: Injector
---

An injector is used to add static code snippet to the `<head>` or/and `<body>` of generated HTML files. Hexo run injector **before** `after_render:html` filter is executed.

## Synopsis

```js
hexo.extend.injector.register(entry, value, to)
```

### entry `<string>`

Where the code will be injected inside the HTML.

Support those values:

- `head_begin`: Inject code snippet right after `<head>` (Default).
- `head_end`: Inject code snippet right before `</head>`.
- `body_begin`: Inject code snippet right after `<body>`.
- `body_end`: Inject code snippet right before `</body>`.

### value `<string> | <Function>`

> A function that returns string is supported.

The code snippet to be injected.

### to `<string>`

Which page will code snippets being injected.

- `default`: Inject to every page (Default).
- `home`: Only inject to home page (which has `is_home()` helper being `true`)
- `post`: Only inject to post pages (which has `is_post()` helper being `true`)
- `page`: Only inject to pages (which has `is_page()` helper being `true`)
- `archive`: Only inject to archive pages (which has `is_archive()` helper being `true`)
- `category`: Only inject to category pages (which has `is_category()` helper being `true`)
- `tag`: Only inject to tag pages (which has `is_tag()` helper being `true`)
- Custom layout name could be used as well, see [Writing - Layout](writing#Layout).

----

There are other internal functions, see [hexojs/hexo#4049](https://github.com/hexojs/hexo/pull/4049) for more details.

## Example

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

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
}, 'music');

hexo.extend.injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.js">', 'music');

hexo.extend.injector.register('body_end', () => {
return js('/js/jquery.js');
});
```

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.
63 changes: 63 additions & 0 deletions source/th/api/injector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
title: Injector
---

An injector is used to add static code snippet to the `<head>` or/and `<body>` of generated HTML files. Hexo run injector **before** `after_render:html` filter is executed.

## Synopsis

```js
hexo.extend.injector.register(entry, value, to)
```

### entry `<string>`

Where the code will be injected inside the HTML.

Support those values:

- `head_begin`: Inject code snippet right after `<head>` (Default).
- `head_end`: Inject code snippet right before `</head>`.
- `body_begin`: Inject code snippet right after `<body>`.
- `body_end`: Inject code snippet right before `</body>`.

### value `<string> | <Function>`

> A function that returns string is supported.

The code snippet to be injected.

### to `<string>`

Which page will code snippets being injected.

- `default`: Inject to every page (Default).
- `home`: Only inject to home page (which has `is_home()` helper being `true`)
- `post`: Only inject to post pages (which has `is_post()` helper being `true`)
- `page`: Only inject to pages (which has `is_page()` helper being `true`)
- `archive`: Only inject to archive pages (which has `is_archive()` helper being `true`)
- `category`: Only inject to category pages (which has `is_category()` helper being `true`)
- `tag`: Only inject to tag pages (which has `is_tag()` helper being `true`)
- Custom layout name could be used as well, see [Writing - Layout](writing#Layout).

----

There are other internal functions, see [hexojs/hexo#4049](https://github.com/hexojs/hexo/pull/4049) for more details.

## Example

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

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
}, 'music');

hexo.extend.injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.js">', 'music');

hexo.extend.injector.register('body_end', () => {
return js('/js/jquery.js');
});
```

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.
61 changes: 61 additions & 0 deletions source/zh-cn/api/injector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
title: 注入器(Injector)
---

注入器被用于将静态代码片段注入生成的 HTML 的 `<head>` 和/或 `<body>` 中。Hexo 将在 `after_render:html` 过滤器 **之前** 完成注入。

## 概要

```js
hexo.extend.injector.register(entry, value, to)
```

### entry `<string>`

代码片段注入的位置,接受以下值:

- `head_begin`: 注入在 `<head>` 之后(默认)
- `head_end`: 注入在 `</head>` 之前
- `body_begin`: 注入在 `<body>` 之后
- `body_end`: 注入在 `</body>` 之前

### value `<string> | <Function>`

> 除了字符串,也支持返回值为字符串的函数

需要注入的代码片段。

### to `<string>`

需要注入代码片段的页面类型,接受以下值:

- `default`: 注入到每个页面(默认值)
- `home`: 只注入到主页(`is_home()` 为 `true` 的页面)
- `post`: 只注入到文章页面(`is_post()` 为 `true` 的页面)
- `page`: 只注入到独立页面(`is_page()` 为 `true` 的页面)
- `archive`: 只注入到归档页面(`is_archive()` 为 `true` 的页面)
- `category`: 只注入到分类页面(`is_category()` 为 `true` 的页面)
- `tag`: 只注入到标签页面(`is_tag()` 为 `true` 的页面)
- 或是其他自定义 layout 名称,自定义 layout 参见 [写作 - 布局(Layout)](writing#Layout)

----

注入器还有一些内部函数,如果你要使用它们,请参考 [hexojs/hexo#4049](https://github.com/hexojs/hexo/pull/4049)。

## 样例

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

hexo.extend.injector.register('head_end', () => {
return css('https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.css');
}, 'music');

hexo.extend.injector.register('body_end', '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/APlayer.min.js">', 'music');

hexo.extend.injector.register('body_end', () => {
return js('/js/jquery.js');
});
```

上述代码将会把 `APlayer.min.css`(`<link>` 标签)和 `APlayer.min.js` (`<script>` 标签)注入到所有 layout 为 `music` 的页面的 `</head>` 和 `</body>` 之前,以及将 `jquery.js`(`<script>` 标签)注入到每一个生成的页面的 `</body>` 之前。
Loading