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(api/filter): before_post_render & after_post_render process all files #1506

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 22 additions & 2 deletions source/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,45 @@ Executed before a post is rendered. Refer to [post rendering](posts.html#Render)
For example, to transform the title to lower case:

``` js
hexo.extend.filter.register('before_post_render', function(data){
hexo.extend.filter.register('before_post_render', function(data) {
data.title = data.title.toLowerCase();
return data;
});
```

This filter processes everything in the `source/` folder; depending on your use case, you may need to skip certain location or file type. Files listed in [`config.skip_render`](/docs/configuration#Directory) and `themes/<your-theme>/source/` folder are not processed by this filter.

``` js
hexo.extend.filter.register('before_post_render', function(data) {
// Target markdown files
if (data.source.endsWith('.md')) {
data.title = data.title.toUpperCase();
}

// Target "_posts/" folder only
if (data.source.startsWith('_posts/')) {
data.title = data.title.toLowerCase();
}

return data;
});
```

### after_post_render

Executed after a post is rendered. Refer to [post rendering](posts.html#Render) to learn the execution steps.

For example, to replace `@username` with a link to a Twitter profile:

``` js
hexo.extend.filter.register('after_post_render', function(data){
hexo.extend.filter.register('after_post_render', function(data) {
data.content = data.content.replace(/@(\d+)/, '<a href="http://twitter.com/$1">#$1</a>');
return data;
});
```

This filter matches every files in the `source/` folder, see [`before_post_render`](#before-post-render) section for more details.

### before_exit

Executed before Hexo is about to exit -- this will run right after `hexo.exit` is called.
Expand Down
24 changes: 22 additions & 2 deletions source/ko/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,30 @@ Post가 생성되기 전에 실행됩니다. 실행 단계에 대해 더 알아
아래 예시는 title을 소문자로 변경하는 것을 보여줍니다.

``` js
hexo.extend.filter.register('before_post_render', function(data){
hexo.extend.filter.register('before_post_render', function(data) {
data.title = data.title.toLowerCase();
return data;
});
```

This filter processes everything in the `source/` folder; depending on your use case, you may need to skip certain location or file type. Files listed in [`config.skip_render`](/docs/configuration#Directory) and `themes/<your-theme>/source/` folder are not processed by this filter.

``` js
hexo.extend.filter.register('before_post_render', function(data) {
// Target markdown files
if (data.source.endsWith('.md')) {
data.title = data.title.toUpperCase();
}

// Target "_posts/" folder only
if (data.source.startsWith('_posts/')) {
data.title = data.title.toLowerCase();
}

return data;
});
```

### after_post_render

Post가 생성된 후 실행됩니다.
Expand All @@ -112,12 +130,14 @@ Executed after a post is rendered. 실행 단계에 대해 더 알아보시길
아래 예시는 `@username`을 Twitter link로 대체하는 것을 보여줍니다.

``` js
hexo.extend.filter.register('after_post_render', function(data){
hexo.extend.filter.register('after_post_render', function(data) {
data.content = data.content.replace(/@(\d+)/, '<a href="http://twitter.com/$1">#$1</a>');
return data;
});
```

This filter matches every files in the `source/` folder, see [`before_post_render`](#before-post-render) section for more details.

### before_exit

Hexo가 종료되기 전에 실행됩니다. -- `hexo.exit`가 호출되는 즉시 실행됩니다.
Expand Down
24 changes: 22 additions & 2 deletions source/pt-br/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,45 @@ Executado antes de uma postagem ser renderizada. Verificar a seção [Renderizar
Por exemplo, para se transformar um título em _caixa baixa_:

``` js
hexo.extend.filter.register('before_post_render', function(data){
hexo.extend.filter.register('before_post_render', function(data) {
data.title = data.title.toLowerCase();
return data;
});
```

This filter processes everything in the `source/` folder; depending on your use case, you may need to skip certain location or file type. Files listed in [`config.skip_render`](/docs/configuration#Directory) and `themes/<your-theme>/source/` folder are not processed by this filter.

``` js
hexo.extend.filter.register('before_post_render', function(data) {
// Target markdown files
if (data.source.endsWith('.md')) {
data.title = data.title.toUpperCase();
}

// Target "_posts/" folder only
if (data.source.startsWith('_posts/')) {
data.title = data.title.toLowerCase();
}

return data;
});
```

### after_post_render

Executado após a postagem ser renderizado. Verificar a seção [Renderizar](posts.html#Renderizar) para saber mais sobre as etapas de execução.

Por exemplo, para substituir `@username` por um link para o perfil do Twitter:

``` js
hexo.extend.filter.register('after_post_render', function(data){
hexo.extend.filter.register('after_post_render', function(data) {
data.content = data.content.replace(/@(\d+)/, '<a href="http://twitter.com/$1">#$1</a>');
return data;
});
```

This filter matches every files in the `source/` folder, see [`before_post_render`](#before-post-render) section for more details.

### before_exit

Executado quando o Hexo está prestes a ser terminado -- isso será executado logo após `hexo.exit` ser chamado.
Expand Down
24 changes: 22 additions & 2 deletions source/ru/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,45 @@ hexo.extend.filter.unregister('example', require('path/to/filter'));
Например, перевести название в нижний регистр:

``` js
hexo.extend.filter.register('before_post_render', function(data){
hexo.extend.filter.register('before_post_render', function(data) {
data.title = data.title.toLowerCase();
return data;
});
```

This filter processes everything in the `source/` folder; depending on your use case, you may need to skip certain location or file type. Files listed in [`config.skip_render`](/docs/configuration#Directory) and `themes/<your-theme>/source/` folder are not processed by this filter.

``` js
hexo.extend.filter.register('before_post_render', function(data) {
// Target markdown files
if (data.source.endsWith('.md')) {
data.title = data.title.toUpperCase();
}

// Target "_posts/" folder only
if (data.source.startsWith('_posts/')) {
data.title = data.title.toLowerCase();
}

return data;
});
```

### after_post_render

Выполняется после завершения обработки поста. См. [post rendering](posts.html#Обработка) для изучения этапов выполнения.

Например, чтобы заменить `@username` ссылкой на профиль в Twitter:

``` js
hexo.extend.filter.register('after_post_render', function(data){
hexo.extend.filter.register('after_post_render', function(data) {
data.content = data.content.replace(/@(\d+)/, '<a href="http://twitter.com/$1">#$1</a>');
return data;
});
```

This filter matches every files in the `source/` folder, see [`before_post_render`](#before-post-render) section for more details.

### before_exit

Выполняется перед выходом из Hexo. Срабатывает сразу после выполнения `hexo.exit`.
Expand Down
24 changes: 22 additions & 2 deletions source/th/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,45 @@ execute ก่อนการ render ของโพสต์ สำหรั
ยกตัวอย่างเช่น การเปลี่ยนตัวอักษรเป็นตัวเล็ก:

``` js
hexo.extend.filter.register('before_post_render', function(data){
hexo.extend.filter.register('before_post_render', function(data) {
data.title = data.title.toLowerCase();
return data;
});
```

This filter processes everything in the `source/` folder; depending on your use case, you may need to skip certain location or file type. Files listed in [`config.skip_render`](/docs/configuration#Directory) and `themes/<your-theme>/source/` folder are not processed by this filter.

``` js
hexo.extend.filter.register('before_post_render', function(data) {
// Target markdown files
if (data.source.endsWith('.md')) {
data.title = data.title.toUpperCase();
}

// Target "_posts/" folder only
if (data.source.startsWith('_posts/')) {
data.title = data.title.toLowerCase();
}

return data;
});
```

### after_post_render

execute หลังการ render ของโพสต์ สำหรับขั้นตอนของ execution ไปดูท่ี [post rendering](posts.html#Render) ได้

ยกตัวอย่างเช่น แทน `@username` ด้วยลิงค์ท่ีชึ้ไปถึงโปรไฟล์ของ Twitter

``` js
hexo.extend.filter.register('after_post_render', function(data){
hexo.extend.filter.register('after_post_render', function(data) {
data.content = data.content.replace(/@(\d+)/, '<a href="http://twitter.com/$1">#$1</a>');
return data;
});
```

This filter matches every files in the `source/` folder, see [`before_post_render`](#before-post-render) section for more details.

### before_exit

execute ก่อนการท่ีจะจบการใช้โปรแกรม hexo -- รันหลังการเรียก `hexo.exit`
Expand Down
24 changes: 22 additions & 2 deletions source/zh-cn/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,45 @@ hexo.extend.filter.unregister('example', require('path/to/filter'));
举例来说,把标题转为小写:

``` js
hexo.extend.filter.register('before_post_render', function(data){
hexo.extend.filter.register('before_post_render', function(data) {
data.title = data.title.toLowerCase();
return data;
});
```

This filter processes everything in the `source/` folder; depending on your use case, you may need to skip certain location or file type. Files listed in [`config.skip_render`](/docs/configuration#Directory) and `themes/<your-theme>/source/` folder are not processed by this filter.

``` js
hexo.extend.filter.register('before_post_render', function(data) {
// Target markdown files
if (data.source.endsWith('.md')) {
data.title = data.title.toUpperCase();
}

// Target "_posts/" folder only
if (data.source.startsWith('_posts/')) {
data.title = data.title.toLowerCase();
}

return data;
});
```

### after_post_render

在文章渲染完成后执行。您可以参考 [文章渲染](posts.html#渲染) 以了解执行顺序。

举例来说,把 `@username` 取代为 Twitter 的开发者链接。

``` js
hexo.extend.filter.register('after_post_render', function(data){
hexo.extend.filter.register('after_post_render', function(data) {
data.content = data.content.replace(/@(\d+)/, '<a href="http://twitter.com/$1">#$1</a>');
return data;
});
```

This filter matches every files in the `source/` folder, see [`before_post_render`](#before-post-render) section for more details.

### before_exit

在 Hexo 即将结束时执行,也就是在 `hexo.exit` 被调用后执行。
Expand Down
24 changes: 22 additions & 2 deletions source/zh-tw/api/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,45 @@ hexo.extend.filter.unregister('example', require('path/to/filter'));
舉例來說,把標題轉為小寫:

``` js
hexo.extend.filter.register('before_post_render', function(data){
hexo.extend.filter.register('before_post_render', function(data) {
data.title = data.title.toLowerCase();
return data;
});
```

This filter processes everything in the `source/` folder; depending on your use case, you may need to skip certain location or file type. Files listed in [`config.skip_render`](/docs/configuration#Directory) and `themes/<your-theme>/source/` folder are not processed by this filter.

``` js
hexo.extend.filter.register('before_post_render', function(data) {
// Target markdown files
if (data.source.endsWith('.md')) {
data.title = data.title.toUpperCase();
}

// Target "_posts/" folder only
if (data.source.startsWith('_posts/')) {
data.title = data.title.toLowerCase();
}

return data;
});
```

### after_post_render

在文章渲染完成後執行。您可參考 [文章渲染](posts.html#渲染) 以瞭解執行順序。

舉例來說,把 `@username` 取代為 Twitter 的使用者連結。

``` js
hexo.extend.filter.register('after_post_render', function(data){
hexo.extend.filter.register('after_post_render', function(data) {
data.content = data.content.replace(/@(\d+)/, '<a href="http://twitter.com/$1">#$1</a>');
return data;
});
```

This filter matches every files in the `source/` folder, see [`before_post_render`](#before-post-render) section for more details.

### before_exit

在 Hexo 即將結束時執行,也就是在 `hexo.exit` 被呼叫後執行。
Expand Down