From f48c6e511712033521fab86b9ae4ec498d5632da Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:18:49 +0800 Subject: [PATCH 01/22] en/api --- source/api/box.md | 41 +++++++++--------- source/api/console.md | 47 +++++++++++--------- source/api/deployer.md | 5 ++- source/api/events.md | 13 +++--- source/api/filter.md | 96 +++++++++++++++++++++-------------------- source/api/generator.md | 71 +++++++++++++++--------------- source/api/helper.md | 19 ++++---- source/api/index.md | 52 +++++++++++----------- source/api/injector.md | 68 ++++++++++++++++------------- source/api/locals.md | 27 ++++++------ source/api/migrator.md | 5 ++- source/api/posts.md | 54 +++++++++++------------ source/api/processor.md | 7 +-- source/api/renderer.md | 79 +++++++++++++++++++-------------- source/api/rendering.md | 39 +++++++++-------- source/api/router.md | 41 +++++++++--------- source/api/scaffolds.md | 7 +-- source/api/tag.md | 89 ++++++++++++++++++++++++-------------- source/api/themes.md | 13 +++--- 19 files changed, 423 insertions(+), 350 deletions(-) diff --git a/source/api/box.md b/source/api/box.md index 3cf4ebe3d9..17f9b22d6a 100644 --- a/source/api/box.md +++ b/source/api/box.md @@ -1,18 +1,19 @@ --- title: Box --- + Box is a container used for processing files in a specified folder. Hexo uses two different boxes: `hexo.source` and `hexo.theme`. The former is used to process the `source` folder and the latter to process the `theme` folder. ## Load Files Box provides two methods for loading files: `process` and `watch`. `process` loads all files in the folder. `watch` does the same, but also starts watching for file changes. -``` js -box.process().then(function(){ +```js +box.process().then(function () { // ... }); -box.watch().then(function(){ +box.watch().then(function () { // You can call box.unwatch() later to stop watching. }); ``` @@ -21,7 +22,7 @@ box.watch().then(function(){ Box provides many ways for path matching. You can use a regular expression, a function or an Express-style pattern string. For example: -``` plain +```plain posts/:id => posts/89 posts/*path => posts/2015/title ``` @@ -32,30 +33,30 @@ See [util.Pattern] for more info. A processor is an essential element of Box and is used to process files. You can use path matching as described above to restrict what exactly the processor should process. Register a new processor with the `addProcessor` method. -``` js -box.addProcessor('posts/:id', function(file){ +```js +box.addProcessor("posts/:id", function (file) { // }); ``` Box passes the content of matched files to processors. This information can then be read straight from the `file` argument in the callback: -Attribute | Description ---- | --- -`source` | Full path of the file -`path` | Relative path to the box of the file -`type` | File type. The value can be `create`, `update`, `skip`, `delete`. -`params` | The information from path matching. +| Attribute | Description | +| --------- | ----------------------------------------------------------------- | +| `source` | Full path of the file | +| `path` | Relative path to the box of the file | +| `type` | File type. The value can be `create`, `update`, `skip`, `delete`. | +| `params` | The information from path matching. | Box also provides some methods so you don't have to do file IO by yourself. -Method | Description ---- | --- -`read` | Read a file -`readSync` | Read a file synchronously -`stat` | Read the status of a file -`statSync` | Read the status of a file synchronously -`render` | Render a file -`renderSync` | Render a file synchronously +| Method | Description | +| ------------ | --------------------------------------- | +| `read` | Read a file | +| `readSync` | Read a file synchronously | +| `stat` | Read the status of a file | +| `statSync` | Read the status of a file synchronously | +| `render` | Render a file | +| `renderSync` | Render a file synchronously | [util.Pattern]: https://github.com/hexojs/hexo-util#patternrule diff --git a/source/api/console.md b/source/api/console.md index 09b05879f1..f03bea2a85 100644 --- a/source/api/console.md +++ b/source/api/console.md @@ -1,21 +1,22 @@ --- title: Console --- + The console forms the bridge between Hexo and its users. It registers and describes the available console commands. ## Synopsis -``` js -hexo.extend.console.register(name, desc, options, function(args){ +```js +hexo.extend.console.register(name, desc, options, function (args) { // ... }); ``` -Argument | Description ---- | --- -`name` | Name -`desc` | Description -`options`| Options +| Argument | Description | +| --------- | ----------- | +| `name` | Name | +| `desc` | Description | +| `options` | Options | An argument `args` will be passed into the function. This is the argument that users type into the terminal. It's parsed by [Minimist]. @@ -25,8 +26,10 @@ An argument `args` will be passed into the function. This is the argument that u The usage of a console command. For example: -``` js -{usage: '[layout]
Test
``` @@ -441,13 +442,13 @@ See [Rendering](https://hexo.io/api/rendering) for more details. Wraps text into lines no longer than `length`. `length` is 80 by default. -``` js +```js <%- word_wrap(str, [length]) %> ``` **Examples:** -``` js +```js <%- word_wrap('Once upon a time', 8) %> // Once upon\n a time ``` @@ -456,13 +457,13 @@ Wraps text into lines no longer than `length`. `length` is 80 by default. Truncates text after certain `length`. Default is 30 characters. -``` js +```js <%- truncate(text, [options]) %> ``` **Examples:** -``` js +```js <%- truncate('Once upon a time in a world far far away', {length: 17}) %> // Once upon a ti... @@ -477,13 +478,13 @@ Truncates text after certain `length`. Default is 30 characters. Escapes HTML entities in a string. -``` js +```js <%- escape_html(str) %> ``` **Examples:** -``` js +```js <%- escape_html('Hello "world".
') %> // <p>Hello "world".</p> ``` @@ -494,26 +495,26 @@ Escapes HTML entities in a string. Loads other template files. You can define local variables in `locals`. -``` js +```js <%- partial(layout, [locals], [options]) %> ``` -Option | Description | Default ---- | --- | --- -`cache` | Cache contents (Use fragment cache) | `false` -`only` | Strict local variables. Only use variables set in `locals` in templates. | `false` +| Option | Description | Default | +| ------- | ------------------------------------------------------------------------ | ------- | +| `cache` | Cache contents (Use fragment cache) | `false` | +| `only` | Strict local variables. Only use variables set in `locals` in templates. | `false` | ### fragment_cache Caches the contents in a fragment. It saves the contents within a fragment and serves the cache when the next request comes in. -``` js +```js <%- fragment_cache(id, fn); ``` **Examples:** -``` js +```js <%- fragment_cache('header', function(){ return '