Skip to content
Open
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
62 changes: 62 additions & 0 deletions source/fa/api/box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
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 () {
// ...
});

box.watch().then(function () {
// You can call box.unwatch() later to stop watching.
});
```

## Path Matching

Box provides many ways for path matching. You can use a regular expression, a function or an Express-style pattern string. For example:

```plain
posts/:id => posts/89
posts/*path => posts/2015/title
```

See [util.Pattern][] for more info.

## Processors

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) {
//
});
```

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. |

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 |

[util.Pattern]: https://github.com/hexojs/hexo-util#patternrule
75 changes: 75 additions & 0 deletions source/fa/api/console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
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) {
// ...
});
```

| 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][].

## Options

### usage

The usage of a console command. For example:

```js
{
usage: "[layout] <title>";
}
// hexo new [layout] <title>
```

### arguments

The description of each argument of a console command. For example:

```js
{
arguments: [
{ name: "layout", desc: "Post layout" },
{ name: "title", desc: "Post title" },
];
}
```

### options

The description of each option of a console command. For example:

```js
{
options: [{ name: "-r, --replace", desc: "Replace existing files" }];
}
```

### desc

More detailed information about a console command.

## Example

```js
hexo.extend.console.register(
"config",
"Display configuration",
function (args) {
console.log(hexo.config);
},
);
```

[Minimist]: https://github.com/minimistjs/minimist
15 changes: 15 additions & 0 deletions source/fa/api/deployer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Deployer
---

A deployer helps users quickly deploy their site to a remote server without complicated commands.

## Synopsis

```js
hexo.extend.deployer.register(name, function (args) {
// ...
});
```

An argument `args` will be passed into the function. It contains the `deploy` value set in `_config.yml`, as well as the exact input users typed into their terminal.
54 changes: 54 additions & 0 deletions source/fa/api/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: Events
---

Hexo inherits from [EventEmitter][]. Use the `on` method to listen for events emitted by Hexo, and use the `emit` method to emit events. For more information, refer to the Node.js API documentation.

### deployBefore

Emitted before deployment begins.

### deployAfter

Emitted after deployment finishes.

### exit

Emitted before Hexo exits.

### generateBefore

Emitted before generation begins.

### generateAfter

Emitted after generation finishes.

### new

Emitted after a new post has been created. This event returns the post data:

```js
hexo.on("new", function (post) {
//
});
```

| Data | Description |
| -------------- | -------------------------- |
| `post.path` | Full path of the post file |
| `post.content` | Content of the post file |

### processBefore

Emitted before processing begins. This event returns a path representing the root directory of the box.

### processAfter

Emitted after processing finishes. This event returns a path representing the root directory of the box.

### ready

Emitted after initialization finishes.

[EventEmitter]: https://nodejs.org/dist/latest/docs/api/events.html
Loading