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

style: apply prettier formatting to md #2145

Merged
merged 25 commits into from
Jun 28, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"build": "hexo generate",
"eslint": "eslint .",
"format:md": "prettier --write */**/docs/*.md */**/api/*.md",
"prepare": "husky"
},
"dependencies": {
Expand All @@ -32,13 +33,15 @@
"eslint-config-hexo": "^5.0.0",
"husky": "^9.0.6",
"imagemin-lint-staged": "^0.5.1",
"lint-staged": "^15.2.0"
"lint-staged": "^15.2.0",
"prettier": "3.2.5"
},
"lint-staged": {
"*.{png,jpeg,jpg,gif,svg}": [
"imagemin-lint-staged"
],
"*.js": "eslint --fix"
"*.js": "eslint --fix",
"*.md": "prettier --write"
},
"engines": {
"node": ">=14"
Expand Down
41 changes: 21 additions & 20 deletions source/api/box.md
Original file line number Diff line number Diff line change
@@ -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.
});
```
Expand All @@ -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
```
Expand All @@ -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
47 changes: 26 additions & 21 deletions source/api/console.md
Original file line number Diff line number Diff line change
@@ -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].

Expand All @@ -25,33 +26,33 @@ 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] <title>'}
```js
{
usage: "[layout] <title>";
}
// hexo new [layout] <title>
```

### arguments

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

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

### options

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

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

Expand All @@ -61,10 +62,14 @@ More detailed information about a console command.

## Example

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

[Minimist]: https://github.com/minimistjs/minimist
5 changes: 3 additions & 2 deletions source/api/deployer.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
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){
```js
hexo.extend.deployer.register(name, function (args) {
// ...
});
```
Expand Down
13 changes: 7 additions & 6 deletions source/api/events.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
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
Expand All @@ -27,16 +28,16 @@ Emitted after generation finishes.

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

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

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

### processBefore

Expand Down
Loading